@@ -162,47 +162,51 @@ public static object chr(int value) {
162162 "eval compiles the code as if were an expression\n " +
163163 "single compiles a single statement\n \n " +
164164 "source can either be a string, bytes or an AST object" ) ]
165- public static object compile ( CodeContext /*!*/ context , [ NotNone ] _ast . AST source , [ NotNone ] string filename , [ NotNone ] string mode , object ? flags = null , bool dont_inherit = false , int optimize = - 1 ) {
165+ public static object compile ( CodeContext /*!*/ context , [ NotNone ] _ast . AST source , [ NotNone ] object filename , [ NotNone ] string mode , object ? flags = null , bool dont_inherit = false , int optimize = - 1 ) {
166166 // TODO: implement optimize
167167
168+ string sfilename = PythonOps . FsPathDecoded ( context , filename ) ;
168169 ValidateCompileMode ( mode ) ;
169170
170171 bool astOnly = flags != null && ( Converter . ConvertToInt32 ( flags ) & _ast . PyCF_ONLY_AST ) != 0 ;
171172
172173 if ( astOnly ) {
173174 return source ;
174175 } else {
175- PythonAst ast = _ast . ConvertToPythonAst ( context , ( _ast . AST ) source , filename ) ;
176+ PythonAst ast = _ast . ConvertToPythonAst ( context , ( _ast . AST ) source , sfilename ) ;
176177 ast . Bind ( ) ;
177178 ScriptCode code = ast . ToScriptCode ( ) ;
178179 return ( ( RunnableScriptCode ) code ) . GetFunctionCode ( true ) ;
179180 }
180181 }
181182
182183 [ Documentation ( "" ) ] // provided by first overload
183- public static object compile ( CodeContext /*!*/ context , [ NotNone ] IBufferProtocol source , [ NotNone ] string filename , [ NotNone ] string mode , object ? flags = null , bool dont_inherit = false , int optimize = - 1 ) {
184+ public static object compile ( CodeContext /*!*/ context , [ NotNone ] IBufferProtocol source , [ NotNone ] object filename , [ NotNone ] string mode , object ? flags = null , bool dont_inherit = false , int optimize = - 1 ) {
184185 // TODO: implement optimize
186+
187+ string sfilename = PythonOps . FsPathDecoded ( context , filename ) ;
185188 var sourceCodeKind = ValidateCompileMode ( mode ) ;
186189
187190 using var buffer = source . GetBuffer ( ) ;
188191 byte [ ] bytes = buffer . AsUnsafeArray ( ) ?? buffer . ToArray ( ) ;
189- var contentProvider = new MemoryStreamContentProvider ( context . LanguageContext , bytes , filename ) ;
190- var sourceUnit = context . LanguageContext . CreateSourceUnit ( contentProvider , filename , sourceCodeKind ) ;
192+ var contentProvider = new MemoryStreamContentProvider ( context . LanguageContext , bytes , sfilename ) ;
193+ var sourceUnit = context . LanguageContext . CreateSourceUnit ( contentProvider , sfilename , sourceCodeKind ) ;
191194
192195 return CompileHelper ( context , sourceUnit , mode , flags , dont_inherit ) ;
193196 }
194197
195198 [ Documentation ( "" ) ] // provided by first overload
196- public static object compile ( CodeContext /*!*/ context , [ NotNone ] string source , [ NotNone ] string filename , [ NotNone ] string mode , object ? flags = null , bool dont_inherit = false , int optimize = - 1 ) {
199+ public static object compile ( CodeContext /*!*/ context , [ NotNone ] string source , [ NotNone ] object filename , [ NotNone ] string mode , object ? flags = null , bool dont_inherit = false , int optimize = - 1 ) {
197200 // TODO: implement optimize
198201
202+ string sfilename = PythonOps . FsPathDecoded ( context , filename ) ;
199203 var sourceCodeKind = ValidateCompileMode ( mode ) ;
200204
201205 if ( source . IndexOf ( '\0 ' ) != - 1 ) {
202206 throw PythonOps . TypeError ( "compile() expected string without null bytes" ) ;
203207 }
204208
205- var sourceUnit = context . LanguageContext . CreateSnippet ( source , filename , sourceCodeKind ) ;
209+ var sourceUnit = context . LanguageContext . CreateSnippet ( source , sfilename , sourceCodeKind ) ;
206210
207211 return CompileHelper ( context , sourceUnit , mode , flags , dont_inherit ) ;
208212 }
0 commit comments