Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitabbe870

Browse files
amos402filmor
authored andcommitted
Internal implement Py_CompileString for compat with CPython 3.8.0 (#1000)
1 parent34d8d35 commitabbe870

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

‎src/runtime/pythonengine.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public static PyObject ReloadModule(PyObject module)
503503
/// </remarks>
504504
publicstaticPyObjectModuleFromString(stringname,stringcode)
505505
{
506-
IntPtrc=Runtime.Py_CompileString(code,"none",(IntPtr)257);
506+
IntPtrc=Runtime.Py_CompileString(code,"none",(int)RunFlagType.File);
507507
Runtime.CheckExceptionOccurred();
508508
IntPtrm=Runtime.PyImport_ExecCodeModule(name,c);
509509
Runtime.CheckExceptionOccurred();
@@ -512,7 +512,7 @@ public static PyObject ModuleFromString(string name, string code)
512512

513513
publicstaticPyObjectCompile(stringcode,stringfilename="",RunFlagTypemode=RunFlagType.File)
514514
{
515-
varflag=(IntPtr)mode;
515+
varflag=(int)mode;
516516
IntPtrptr=Runtime.Py_CompileString(code,filename,flag);
517517
Runtime.CheckExceptionOccurred();
518518
returnnewPyObject(ptr);
@@ -610,7 +610,7 @@ internal static PyObject RunString(string code, IntPtr? globals, IntPtr? locals,
610610
}
611611
}
612612

613-
publicenumRunFlagType
613+
publicenumRunFlagType:int
614614
{
615615
Single=256,
616616
File=257,/* Py_file_input */

‎src/runtime/runtime.cs‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,36 @@ public static extern int Py_Main(
763763
[DllImport(_PythonDll,CallingConvention=CallingConvention.Cdecl)]
764764
internalstaticexternIntPtr PyEval_EvalCode(IntPtrco,IntPtrglobals,IntPtrlocals);
765765

766+
#ifPYTHON2
767+
[DllImport(_PythonDll,CallingConvention=CallingConvention.Cdecl)]
768+
internalstaticexternIntPtr Py_CompileString(stringcode,stringfile,intstart);
769+
#else
770+
/// <summary>
771+
/// Return value: New reference.
772+
/// This is a simplified interface to Py_CompileStringFlags() below, leaving flags set to NULL.
773+
/// </summary>
774+
internalstaticIntPtr Py_CompileString(stringstr,stringfile,intstart)
775+
{
776+
returnPy_CompileStringFlags(str,file,start,IntPtr.Zero);
777+
}
778+
779+
/// <summary>
780+
/// Return value: New reference.
781+
/// This is a simplified interface to Py_CompileStringExFlags() below, with optimize set to -1.
782+
/// </summary>
783+
internalstaticIntPtr Py_CompileStringFlags(stringstr,stringfile,intstart,IntPtrflags)
784+
{
785+
return Py_CompileStringExFlags(str,file,start,flags,-1);
786+
}
787+
788+
/// <summary>
789+
/// Return value: New reference.
790+
/// Like Py_CompileStringObject(), but filename is a byte string decoded from the filesystem encoding(os.fsdecode()).
791+
/// </summary>
792+
/// <returns></returns>
766793
[DllImport(_PythonDll,CallingConvention=CallingConvention.Cdecl)]
767-
internalstaticexternIntPtr Py_CompileString(stringcode,stringfile,IntPtrtok);
794+
internalstatic extern IntPtr Py_CompileStringExFlags(string str,stringfile,intstart,IntPtrflags,intoptimize);
795+
#endif
768796

769797
[DllImport(_PythonDll,CallingConvention=CallingConvention.Cdecl)]
770798
internalstaticexternIntPtr PyImport_ExecCodeModule(stringname,IntPtrcode);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp