Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38b3f01

Browse files
committed
classderived: handle tp_dealloc called after tp_clear
Because tp_clear sets tpHandle to NULL, it can't be used. Fortunately, we can simply read object's type from pyHandle.
1 parent 9682dc6 commit 38b3f01

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/runtime/classderived.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ internal ClassDerivedObject(Type tp) : base(tp)
7575
// So we don't call PyObject_GC_Del here and instead we set the python
7676
// reference to a weak reference so that the C# object can be collected.
7777
GCHandle gc = GCHandle.Alloc(self, GCHandleType.Weak);
78-
Marshal.WriteIntPtr(self.pyHandle, ObjectOffset.magic(self.tpHandle), (IntPtr)gc);
78+
int gcOffset = ObjectOffset.magic(Runtime.PyObject_TYPE(self.pyHandle));
79+
Marshal.WriteIntPtr(self.pyHandle, gcOffset, (IntPtr)gc);
7980
self.gcHandle.Free();
8081
self.gcHandle = gc;
8182
}

0 commit comments

Comments
 (0)