8000 make PyModule_AddObject in line with CPython · pythonnet/pythonnet@bd7e745 · GitHub
[go: up one dir, main page]

Skip to content

Commit bd7e745

Browse files
committed
make PyModule_AddObject in line with CPython
1 par
8000
ent 624f7e3 commit bd7e745

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/runtime/importhook.cs

Lines changed: 1 addition & 1 deletion
Runtime.PyObject_Call(exec, args, default);
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void SetupImportHook()
122122
Runtime.PyTuple_SetItem(args, 1, mod_dict);
123123
124124
// Set as a sub-module of clr.
125-
if(Runtime.PyModule_AddObject(ClrModuleReference, "loader", import_hook_module) != 0)
125+
if(Runtime.PyModule_AddObject(ClrModuleReference, "loader", import_hook_module.DangerousGetAddress()) != 0)
126126
{
127127
Runtime.XDecref(import_hook_module.DangerousGetAddress());
128128
throw PythonException.ThrowLastAsClrException();

src/runtime/runtime.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,9 +1934,12 @@ internal static string PyModule_GetFilename(IntPtr module)
19341934
/// </summary>
19351935
/// <param name="module">The module to add the object to.</param>
19361936
/// <param name="name">The key that will refer to the object.</param>
1937-
/// <param name="stolenObject">The object to add to the module.</param>
1937+
/// <param name="stolenObject">
1938+
/// The object to add to the module. The reference will be stolen only if the
1939+
/// method returns 0.
1940+
/// </param>
19381941
/// <returns>Return -1 on error, 0 on success.</returns>
1939-
internal static int PyModule_AddObject(BorrowedReference module, string name, BorrowedReference stolenObject)
1942+
internal static int PyModule_AddObject(BorrowedReference module, string name, IntPtr stolenObject)
19401943
{
19411944
using var namePtr = new StrPtr(name, Encoding.UTF8);
19421945
return Delegates.PyModule_AddObject(module, namePtr, stolenObject);
@@ -2498,7 +2501,7 @@ static Delegates()
24982501
{
24992502
PyModule_Create2 = (delegate* unmanaged[Cdecl]<IntPtr, int, IntPtr>)GetFunctionByName("PyModule_Create2TraceRefs", GetUnmanagedDll(_PythonDll));
25002503
}
2501-
PyModule_AddObject = (delegate* unmanaged[Cdecl]<BorrowedReference, StrPtr, BorrowedReference, int>)GetFunctionByName(nameof(PyModule_AddObject), GetUnmanagedDll(_PythonDll));
2504+
PyModule_AddObject = (delegate* unmanaged[Cdecl]<BorrowedReference, StrPtr, IntPtr, int>)GetFunctionByName(nameof(PyModule_AddObject), GetUnmanagedDll(_PythonDll));
25022505
PyImport_Import = (delegate* unmanaged[Cdecl]<IntPtr, IntPtr>)GetFunctionByName(nameof(PyImport_Import), GetUnmanagedDll(_PythonDll));
25032506
PyImport_ImportModule = (delegate* unmanaged[Cdecl]<StrPtr, NewReference>)GetFunctionByName(nameof(PyImport_ImportModule), GetUnmanagedDll(_PythonDll));
25042507
PyImport_ReloadModule = (delegate* unmanaged[Cdecl]<BorrowedReference, NewReference>)GetFunctionByName(nameof(PyImport_ReloadModule), GetUnmanagedDll(_PythonDll));
@@ -2787,7 +2790,7 @@ static Delegates()
27872790
internal static delegate* unmanaged[Cdecl]<BorrowedReference, BorrowedReference> PyModule_GetDict { get; }
27882791
internal static delegate* unmanaged[Cdecl]<IntPtr, StrPtr> PyModule_GetFilename { get; }
27892792
internal static delegate* unmanaged[Cdecl]<IntPtr, int, IntPtr> PyModule_Create2 { get; }
2790-
internal static delegate* unmanaged[Cdecl]<BorrowedReference, StrPtr, BorrowedReference, int> PyModule_AddObject { get; }
2793+
internal static delegate* unmanaged[Cdecl]<BorrowedReference, StrPtr, IntPtr, int> PyModule_AddObject { get; }
27912794
internal static delegate* unmanaged[Cdecl]<IntPtr, IntPtr> PyImport_Import { get; }
27922795
internal static delegate* unmanaged[Cdecl]<StrPtr, NewReference> PyImport_ImportModule { get; }
27932796
internal static delegate* unmanaged[Cdecl]<BorrowedReference, NewReference> PyImport_ReloadModule { get; }

0 commit comments

Comments
 (0)
0