Skip to content

Commit da835c9

Browse files
committed
added debug message to the assert that fails on Mac to figure out the cause
1 parent d877337 commit da835c9

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/runtime/classbase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,13 @@ static int ClearImpl(IntPtr ob, ManagedType self)
387387
bool isTypeObject = Runtime.PyObject_TYPE(ob) == Runtime.PyCLRMetaType;
388388
if (!isTypeObject)
389389
{
390+
ClearObjectDict(ob);
391+
390392
int baseClearResult = BaseUnmanagedClear(ob);
391393
if (baseClearResult != 0)
392394
{
393395
return baseClearResult;
394396
}
395-
396-
ClearObjectDict(ob);
397397
}
398398
if (self is not null) self.tpHandle = IntPtr.Zero;
399399
return 0;

src/runtime/classderived.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,15 @@ internal ClassDerivedObject(Type tp) : base(tp)
7676
// So we don't call PyObject_GC_Del here and instead we set the python
7777
// reference to a weak reference so that the C# object can be collected.
7878
GCHandle gc = GCHandle.Alloc(self, GCHandleType.Weak);
79-
Debug.Assert(self.TypeReference == Runtime.PyObject_TYPE(self.ObjectReference));
79+
#if DEBUG
80+
BorrowedReference instanceType = Runtime.PyObject_TYPE(self.ObjectReference);
81+
if (self.TypeReference != instanceType)
82+
{
83+
using var type = new PyObject(self.TypeReference);
84+
using var instType = new PyObject(instanceType);
85+
Debug.Fail($"{type} vs {instType}");
86+
}
87+
#endif
8088
SetGCHandle(self.ObjectReference, self.TypeReference, gc);
8189
self.gcHandle.Free();
8290
self.gcHandle = gc;

0 commit comments

Comments
 (0)