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

Skip to content

Commit 027e529

Browse files
committed
switched debughelper.cs to the new style references
1 parent 9b990c1 commit 027e529

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

src/runtime/debughelper.cs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,18 @@ namespace Python.Runtime
1414
internal class DebugUtil
1515
{
1616
[Conditional("DEBUG")]
17-
public static void Print(string msg, params IntPtr[] args)
17+
public static void Print(string msg, BorrowedReference member)
1818
{
1919
string result = msg;
2020
result += " ";
2121

22-
foreach (IntPtr t in args)
22+
if (member == null)
2323
{
24-
if (t == IntPtr.Zero)
25-
{
26-
Console.WriteLine("null arg to print");
27-
}
28-
IntPtr ob = Runtime.PyObject_Repr(t);
29-
result += Runtime.GetManagedString(ob);
30-
Runtime.XDecref(ob);
31-
result += " ";
24+
Console.WriteLine("null arg to print");
3225
}
26+
using var ob = Runtime.PyObject_Repr(member);
27+
result += Runtime.GetManagedString(ob.BorrowOrThrow());
28+
result += " ";
3329
Console.WriteLine(result);
3430
}
3531

@@ -40,21 +36,21 @@ public static void Print(string msg)
4036
}
4137

4238
[Conditional("DEBUG")]
43-
internal static void DumpType(IntPtr type)
39+
internal static void DumpType(BorrowedReference type)
4440
{
45-
IntPtr op = Marshal.ReadIntPtr(type, TypeOffset.tp_name);
41+
IntPtr op = Util.ReadIntPtr(type, TypeOffset.tp_name);
4642
string name = Marshal.PtrToStringAnsi(op);
4743

4844
Console.WriteLine("Dump type: {0}", name);
4945

50-
op = Marshal.ReadIntPtr(type, TypeOffset.ob_type);
51-
Print(" type: ", op);
46+
var objMember = Util.ReadRef(type, TypeOffset.ob_type);
47+
Print(" type: ", objMember);
5248

53-
op = Marshal.ReadIntPtr(type, TypeOffset.tp_base);
54-
Print(" base: ", op);
49+
objMember = Util.ReadRef(type, TypeOffset.tp_base);
50+
Print(" base: ", objMember);
5551

56-
op = Marshal.ReadIntPtr(type, TypeOffset.tp_bases);
57-
Print(" bases: ", op);
52+
objMember = Util.ReadRef(type, TypeOffset.tp_bases);
53+
Print(" bases: ", objMember);
5854

5955
//op = Marshal.ReadIntPtr(type, TypeOffset.tp_mro);
6056
//DebugUtil.Print(" mro: ", op);
@@ -67,33 +63,33 @@ internal static void DumpType(IntPtr type)
6763
{
6864
int offset = entry.Value;
6965
name = entry.Key;
70-
op = Marshal.ReadIntPtr(type, offset);
66+
op = Util.ReadIntPtr(type, offset);
7167
Console.WriteLine(" {0}: {1}", name, op);
7268
}
7369

7470
Console.WriteLine("");
7571
Console.WriteLine("");
7672

77-
op = Marshal.ReadIntPtr(type, TypeOffset.tp_dict);
78-
if (op == IntPtr.Zero)
73+
objMember = Util.ReadRef(type, TypeOffset.tp_dict);
74+
if (objMember == null)
7975
{
8076
Console.WriteLine(" dict: null");
8177
}
8278
else
8379
{
84-
Print(" dict: ", op);
80+
Print(" dict: ", objMember);
8581
}
8682
}
8783

8884
[Conditional("DEBUG")]
89-
internal static void DumpInst(IntPtr ob)
85+
internal static void DumpInst(BorrowedReference ob)
9086
{
91-
IntPtr tp = Runtime.PyObject_TYPE(ob);
92-
var sz = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_basicsize);
87+
BorrowedReference tp = Runtime.PyObject_TYPE(ob);
88+
nint sz = Util.ReadIntPtr(tp, TypeOffset.tp_basicsize);
9389

94-
for (var i = 0; i < sz; i += IntPtr.Size)
90+
for (nint i = 0; i < sz; i += IntPtr.Size)
9591
{
96-
var pp = new IntPtr(ob.ToInt64() + i);
92+
var pp = new IntPtr(ob.DangerousGetAddress().ToInt64() + i);
9793
IntPtr v = Marshal.ReadIntPtr(pp);
9894
Console.WriteLine("offset {0}: {1}", i, v);
9995
}
@@ -139,9 +135,9 @@ public static void PrintHexBytes(byte[] bytes)
139135
}
140136

141137
[Conditional("DEBUG")]
142-
public static void AssertHasReferences(IntPtr obj)
138+
public static void AssertHasReferences(BorrowedReference obj)
143139
{
144-
long refcount = Runtime.Refcount(obj);
140+
nint refcount = Runtime.Refcount(obj);
145141
Debug.Assert(refcount > 0, "Object refcount is 0 or less");
146142
}
147143

0 commit comments

Comments
 (0)