Skip to content

Commit 2108530

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

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ 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+
Debug.Fail($"{new PyObject(self.TypeReference)} vs {new PyObject(instanceType)}");
84+
}
85+
#endif
8086
SetGCHandle(self.ObjectReference, self.TypeReference, gc);
8187
self.gcHandle.Free();
8288
self.gcHandle = gc;

0 commit comments

Comments
 (0)