Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added a few debug guards
  • Loading branch information
lostmsu committed Sep 23, 2021
commit cb4a3d8736a55ce7a8b80e86839f24c1cd676765
21 changes: 19 additions & 2 deletions src/runtime/managedtype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,23 @@ internal enum TrackTypes
internal IntPtr pyHandle; // PyObject *
internal IntPtr tpHandle; // PyType *

internal BorrowedReference ObjectReference => new(pyHandle);
internal BorrowedReference TypeReference => new(tpHandle);
internal BorrowedReference ObjectReference
{
get
{
Debug.Assert(pyHandle != IntPtr.Zero);
return new(pyHandle);
}
}

internal BorrowedReference TypeReference
{
get
{
Debug.Assert(tpHandle != IntPtr.Zero);
return new(tpHandle);
}
}

private static readonly Dictionary<ManagedType, TrackTypes> _managedObjs = new Dictionary<ManagedType, TrackTypes>();

Expand Down Expand Up @@ -310,6 +325,8 @@ internal static void InitGCHandle(BorrowedReference reflectedClrObject, GCHandle

internal static void SetGCHandle(BorrowedReference reflectedClrObject, BorrowedReference type, GCHandle newHandle)
{
Debug.Assert(type != null);
Debug.Assert(reflectedClrObject != null);
Debug.Assert(Runtime.PyObject_TypeCheck(reflectedClrObject, type));

int offset = Marshal.ReadInt32(type.DangerousGetAddress(), Offsets.tp_clr_inst_offset);
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,11 @@ internal static bool PyType_Check(IntPtr ob)
internal static void PyType_Modified(BorrowedReference type) => Delegates.PyType_Modified(type);
internal static bool PyType_IsSubtype(BorrowedReference t1, IntPtr ofType)
=> PyType_IsSubtype(t1, new BorrowedReference(ofType));
internal static bool PyType_IsSubtype(BorrowedReference t1, BorrowedReference t2) => Delegates.PyType_IsSubtype(t1, t2);
internal static bool PyType_IsSubtype(BorrowedReference t1, BorrowedReference t2)
{
Debug.Assert(t1 != null && t2 != null);
return Delegates.PyType_IsSubtype(t1, t2);
}

internal static bool PyObject_TypeCheck(IntPtr ob, IntPtr tp)
=> PyObject_TypeCheck(new BorrowedReference(ob), new BorrowedReference(tp));
Expand Down