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

Commitaf6d37f

Browse files
committed
Fix the shutdown issue by keeping PyMethodDef.
Keeping the PyMethodDef around like the documentation(https://docs.python.org/3.6/c-api/module.html#c.PyModuleDef) suggestsfixes issue#262.
1 parent9912712 commitaf6d37f

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

‎src/runtime/importhook.cs‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ internal class ImportHook
1616

1717
#ifPYTHON3
1818
staticIntPtrpy_clr_module;
19-
staticIntPtrmodule_def;
19+
staticIntPtrmodule_def=IntPtr.Zero;
20+
21+
internalstaticvoidInitializeModuleDef()
22+
{
23+
if(module_def==IntPtr.Zero)
24+
module_def=ModuleDefOffset.AllocModuleDef("clr");
25+
}
2026
#endif
2127

2228
//===================================================================
@@ -44,8 +50,8 @@ internal static void Initialize()
4450
root=newCLRModule();
4551

4652
#ifPYTHON3
47-
// create a python module with the same methods as the clr module-like object
48-
module_def=ModuleDefOffset.AllocModuleDef("clr");
53+
// create a python module with the same methods as the clr module-like object
54+
InitializeModuleDef();
4955
py_clr_module=Runtime.PyModule_Create2(module_def,3);
5056

5157
// both dicts are borrowed references
@@ -70,21 +76,13 @@ internal static void Initialize()
7076

7177
internalstaticvoidShutdown()
7278
{
73-
#ifPYTHON3
7479
if(0!=Runtime.Py_IsInitialized()){
80+
#ifPYTHON3
7581
Runtime.XDecref(py_clr_module);
76-
Runtime.XDecref(root.pyHandle);
77-
}
78-
ModuleDefOffset.FreeModuleDef(module_def);
7982
#elifPYTHON2
80-
if(0!=Runtime.Py_IsInitialized())
81-
{
82-
Runtime.XDecref(root.pyHandle);
8383
Runtime.XDecref(root.pyHandle);
84-
}
8584
#endif
86-
if(0!=Runtime.Py_IsInitialized())
87-
{
85+
Runtime.XDecref(root.pyHandle);
8886
Runtime.XDecref(py_import);
8987
}
9088
}

‎src/runtime/interop.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public static IntPtr AllocModuleDef(string modulename) {
227227
byte[]ascii=Encoding.ASCII.GetBytes(modulename);
228228
intsize=name+ascii.Length+1;
229229
IntPtrptr=Marshal.AllocHGlobal(size);
230-
for(inti=0;i<=m_free;i+=IntPtr.Size)
230+
for(inti=0;i<m_free;i+=IntPtr.Size)
231231
Marshal.WriteIntPtr(ptr,i,IntPtr.Zero);
232232
Marshal.Copy(ascii,0,(IntPtr)(ptr+name),ascii.Length);
233233
Marshal.WriteIntPtr(ptr,m_name,(IntPtr)(ptr+name));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp