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

Skip to content

Commit b5c222c

Browse files
committed
a few debug helper properties
1 parent bf984f0 commit b5c222c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/runtime/Finalizer.cs

+2
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ struct PendingFinalization
364364
{
365365
public IntPtr PyObj;
366366
public BorrowedReference Ref => new(PyObj);
367+
public ManagedType? Managed => ManagedType.GetManagedObject(Ref);
368+
public nint RefCount => Runtime.Refcount(Ref);
367369
public int RuntimeRun;
368370
#if TRACE_ALLOC
369371
public string StackTrace;

src/runtime/PythonTypes/PyObject.cs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,20 @@ public PyList Dir()
10511051
return Runtime.GetManagedString(strval.BorrowOrThrow());
10521052
}
10531053

1054-
string? DebuggerDisplay => DebugUtil.HaveInterpreterLock()
1055-
? this.ToString()
1056-
: $"pyobj at 0x{this.rawPtr:X} (get Py.GIL to see more info)";
1054+
ManagedType? InternalManagedObject => ManagedType.GetManagedObject(this.Reference);
1055+
1056+
string? DebuggerDisplay
1057+
{
1058+
get
1059+
{
1060+
if (DebugUtil.HaveInterpreterLock())
1061+
return this.ToString();
1062+
var obj = this.InternalManagedObject;
1063+
return obj is { }
1064+
? obj.ToString()
1065+
: $"pyobj at 0x{this.rawPtr:X} (get Py.GIL to see more info)";
1066+
}
1067+
}
10571068

10581069

10591070
/// <summary>

0 commit comments

Comments
 (0)