| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,22 +14,18 @@ namespace Python.Runtime | |||
| 14 | 14 | internal class DebugUtil | |
| 15 | 15 | { | |
| 16 | 16 | [Conditional("DEBUG")] | |
| 17 | - public static void Print(string msg, params IntPtr[] args) | ||
| 17 | + public static void Print(string msg, BorrowedReference member) | ||
| 18 | 18 | { | |
| 19 | 19 | string result = msg; | |
| 20 | 20 | result += " "; | |
| 21 | 21 | ||
| 22 | - foreach (IntPtr t in args) | ||
| 22 | + if (member == null) | ||
| 23 | 23 | { | |
| 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"); | ||
| 32 | 25 | } | |
| 26 | + using var ob = Runtime.PyObject_Repr(member); | ||
| 27 | + result += Runtime.GetManagedString(ob.BorrowOrThrow()); | ||
| 28 | + result += " "; | ||
| 33 | 29 | Console.WriteLine(result); | |
| 34 | 30 | } | |
| 35 | 31 | ||
@@ -40,21 +36,21 @@ public static void Print(string msg) | |||
| 40 | 36 | } | |
| 41 | 37 | ||
| 42 | 38 | [Conditional("DEBUG")] | |
| 43 | - internal static void DumpType(IntPtr type) | ||
| 39 | + internal static void DumpType(BorrowedReference type) | ||
| 44 | 40 | { | |
| 45 | - IntPtr op = Marshal.ReadIntPtr(type, TypeOffset.tp_name); | ||
| 41 | + IntPtr op = Util.ReadIntPtr(type, TypeOffset.tp_name); | ||
| 46 | 42 | string name = Marshal.PtrToStringAnsi(op); | |
| 47 | 43 | ||
| 48 | 44 | Console.WriteLine("Dump type: {0}", name); | |
| 49 | 45 | ||
| 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); | ||
| 52 | 48 | ||
| 53 | - op = Marshal.ReadIntPtr(type, TypeOffset.tp_base); | ||
| 54 | - Print(" base: ", op); | ||
| 49 | + objMember = Util.ReadRef(type, TypeOffset.tp_base); | ||
| 50 | + Print(" base: ", objMember); | ||
| 55 | 51 | ||
| 56 | - op = Marshal.ReadIntPtr(type, TypeOffset.tp_bases); | ||
| 57 | - Print(" bases: ", op); | ||
| 52 | + objMember = Util.ReadRef(type, TypeOffset.tp_bases); | ||
| 53 | + Print(" bases: ", objMember); | ||
| 58 | 54 | ||
| 59 | 55 | //op = Marshal.ReadIntPtr(type, TypeOffset.tp_mro); | |
| 60 | 56 | //DebugUtil.Print(" mro: ", op); | |
@@ -67,33 +63,33 @@ internal static void DumpType(IntPtr type) | |||
| 67 | 63 | { | |
| 68 | 64 | int offset = entry.Value; | |
| 69 | 65 | name = entry.Key; | |
| 70 | - op = Marshal.ReadIntPtr(type, offset); | ||
| 66 | + op = Util.ReadIntPtr(type, offset); | ||
| 71 | 67 | Console.WriteLine(" {0}: {1}", name, op); | |
| 72 | 68 | } | |
| 73 | 69 | ||
| 74 | 70 | Console.WriteLine(""); | |
| 75 | 71 | Console.WriteLine(""); | |
| 76 | 72 | ||
| 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) | ||
| 79 | 75 | { | |
| 80 | 76 | Console.WriteLine(" dict: null"); | |
| 81 | 77 | } | |
| 82 | 78 | else | |
| 83 | 79 | { | |
| 84 | - Print(" dict: ", op); | ||
| 80 | + Print(" dict: ", objMember); | ||
| 85 | 81 | } | |
| 86 | 82 | } | |
| 87 | 83 | ||
| 88 | 84 | [Conditional("DEBUG")] | |
| 89 | - internal static void DumpInst(IntPtr ob) | ||
| 85 | + internal static void DumpInst(BorrowedReference ob) | ||
| 90 | 86 | { | |
| 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); | ||
| 93 | 89 | ||
| 94 | - for (var i = 0; i < sz; i += IntPtr.Size) | ||
| 90 | + for (nint i = 0; i < sz; i += IntPtr.Size) | ||
| 95 | 91 | { | |
| 96 | - var pp = new IntPtr(ob.ToInt64() + i); | ||
| 92 | + var pp = new IntPtr(ob.DangerousGetAddress().ToInt64() + i); | ||
| 97 | 93 | IntPtr v = Marshal.ReadIntPtr(pp); | |
| 98 | 94 | Console.WriteLine("offset {0}: {1}", i, v); | |
| 99 | 95 | } | |
@@ -139,9 +135,9 @@ public static void PrintHexBytes(byte[] bytes) | |||
| 139 | 135 | } | |
| 140 | 136 | ||
| 141 | 137 | [Conditional("DEBUG")] | |
| 142 | - public static void AssertHasReferences(IntPtr obj) | ||
| 138 | + public static void AssertHasReferences(BorrowedReference obj) | ||
| 143 | 139 | { | |
| 144 | - long refcount = Runtime.Refcount(obj); | ||
| 140 | + nint refcount = Runtime.Refcount(obj); | ||
| 145 | 141 | Debug.Assert(refcount > 0, "Object refcount is 0 or less"); | |
| 146 | 142 | } | |
| 147 | 143 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments