8000 Fix refcnt error of qualname · pythonnet/pythonnet@2940973 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2940973

Browse files
committed
Fix refcnt error of qualname
1 parent 2a88be4 commit 2940973

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/runtime/metatype.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public static void Release()
2828
{
2929
SlotsHolder.ReleaseTypeSlots(PyCLRMetaType);
3030
}
31-
// FIXME: Crash on .netcore if decref PyCLRMetaType
32-
// 8000 Runtime.XDecref(PyCLRMetaType);
31+
Runtime.XDecref(PyCLRMetaType);
3332
PyCLRMetaType = IntPtr.Zero;
3433
}
3534

src/runtime/typemanager.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,12 @@ internal static IntPtr CreateMetaType(Type impl)
399399
IntPtr mdefAddr = mdef;
400400
slotsHolder.AddDealloctor(() =>
401401
{
402+
IntPtr t = type;
403+
IntPtr tp_dict = Marshal.ReadIntPtr(t, TypeOffset.tp_dict);
404+
if (Runtime.PyDict_DelItemString(tp_dict, "__instancecheck__") != 0)
405+
{
406+
Runtime.PyErr_Print();
407+
}
402408
FreeMethodDef(mdefAddr);
403409
});
404410
}
@@ -414,6 +420,12 @@ internal static IntPtr CreateMetaType(Type impl)
414420
IntPtr mdefAddr = mdef;
415421
slotsHolder.AddDealloctor(() =>
416422
{
423+
IntPtr t = type;
424+
IntPtr tp_dict = Marshal.ReadIntPtr(t, TypeOffset.tp_dict);
425+
if (Runtime.PyDict_DelItemString(tp_dict, "__subclasscheck__") != 0)
426+
{
427+
Runtime.PyErr_Print();
428+
}
417429
FreeMethodDef(mdefAddr);
418430
});
419431
}
@@ -521,6 +533,7 @@ internal static IntPtr AllocateTypeObject(string name)
521533
Marshal.WriteIntPtr(type, TypeOffset.name, temp);
522534

523535
#if PYTHON3
536+
Runtime.XIncref(temp);
524537
Marshal.WriteIntPtr(type, TypeOffset.qualname, temp);
525538
#endif
526539

@@ -1101,6 +1114,11 @@ private static IntPtr GetDefaultSlot(int offset)
11011114
// tp_free of PyTypeType is point to PyObejct_GC_Del.
11021115
return Marshal.ReadIntPtr(Runtime.PyTypeType, TypeOffset.tp_free);
11031116
}
1117+
else if (offset == TypeOffset.tp_free)
1118+
{
1119+
// PyObject_GC_Del
1120+
return Marshal.ReadIntPtr(Runtime.PyTypeType, TypeOffset.tp_free);
1121+
}
11041122
else if (offset == TypeOffset.tp_call)
11051123
{
11061124
return IntPtr.Zero;
@@ -1110,6 +1128,16 @@ private static IntPtr GetDefaultSlot(int offset)
11101128
// PyType_GenericNew
11111129
return Marshal.ReadIntPtr(Runtime.PySuper_Type, TypeOffset.tp_new);
11121130
}
1131+
else if (offset == TypeOffset.tp_getattro)
1132+
{
1133+
// PyObject_GenericGetAttr
1134+
return Marshal.ReadIntPtr(Runtime.PyBaseObjectType, TypeOffset.tp_getattro);
1135+
}
1136+
else if (offset == TypeOffset.tp_setattro)
1137+
{
1138+
// PyObject_GenericSetAttr
1139+
return Marshal.ReadIntPtr(Runtime.PyBaseObjectType, TypeOffset.tp_setattro);
1140+
}
11131141

11141142
return Marshal.ReadIntPtr(Runtime.PyTypeType, offset);
11151143
}

0 commit comments

Comments
 (0)
0