| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,8 @@ | |||
| 1 | 1 | namespace Python.Runtime | |
| 2 | 2 | { | |
| 3 | 3 | using System; | |
| 4 | + using System.Diagnostics; | ||
| 5 | + | ||
| 4 | 6 | /// <summary> | |
| 5 | 7 | /// Represents a reference to a Python object, that is being lent, and | |
| 6 | 8 | /// can only be safely used until execution returns to the caller. | |
@@ -11,6 +13,7 @@ readonly ref struct BorrowedReference | |||
| 11 | 13 | public bool IsNull => this.pointer == IntPtr.Zero; | |
| 12 | 14 | ||
| 13 | 15 | /// <summary>Gets a raw pointer to the Python object</summary> | |
| 16 | + [DebuggerHidden] | ||
| 14 | 17 | public IntPtr DangerousGetAddress() | |
| 15 | 18 | => this.IsNull ? throw new NullReferenceException() : this.pointer; | |
| 16 | 19 | /// <summary>Gets a raw pointer to the Python object</summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ ref struct NewReference | |||
| 14 | 14 | IntPtr pointer; | |
| 15 | 15 | ||
| 16 | 16 | /// <summary>Creates a <see cref="NewReference"/> pointing to the same object</summary> | |
| 17 | + [DebuggerHidden] | ||
| 17 | 18 | public NewReference(BorrowedReference reference, bool canBeNull = false) | |
| 18 | 19 | { | |
| 19 | 20 | var address = canBeNull | |
@@ -69,13 +70,15 @@ public IntPtr DangerousMoveToPointerOrNull() | |||
| 69 | 70 | /// that steals reference passed to it. | |
| 70 | 71 | /// </summary> | |
| 71 | 72 | [MethodImpl(MethodImplOptions.AggressiveInlining)] | |
| 73 | + [DebuggerHidden] | ||
| 72 | 74 | public StolenReference StealNullable() => StolenReference.TakeNullable(ref this.pointer); | |
| 73 | 75 | ||
| 74 | 76 | /// <summary> | |
| 75 | 77 | /// Call this method to move ownership of this reference to a Python C API function, | |
| 76 | 78 | /// that steals reference passed to it. | |
| 77 | 79 | /// </summary> | |
| 78 | 80 | [MethodImpl(MethodImplOptions.AggressiveInlining)] | |
| 81 | + [DebuggerHidden] | ||
| 79 | 82 | public StolenReference Steal() | |
| 80 | 83 | { | |
| 81 | 84 | if (this.IsNull()) throw new NullReferenceException(); | |
@@ -118,6 +121,7 @@ public static NewReference DangerousFromPointer(IntPtr pointer) | |||
| 118 | 121 | internal static IntPtr DangerousGetAddress(in NewReference reference) | |
| 119 | 122 | => IsNull(reference) ? throw new NullReferenceException() : reference.pointer; | |
| 120 | 123 | [Pure] | |
| 124 | + [DebuggerHidden] | ||
| 121 | 125 | internal static bool IsNull(in NewReference reference) | |
| 122 | 126 | => reference.pointer == IntPtr.Zero; | |
| 123 | 127 | } | |
@@ -131,17 +135,21 @@ static class NewReferenceExtensions | |||
| 131 | 135 | { | |
| 132 | 136 | /// <summary>Gets a raw pointer to the Python object</summary> | |
| 133 | 137 | [Pure] | |
| 138 | + [DebuggerHidden] | ||
| 134 | 139 | public static IntPtr DangerousGetAddress(this in NewReference reference) | |
| 135 | 140 | => NewReference.DangerousGetAddress(reference); | |
| 136 | 141 | [Pure] | |
| 142 | + [DebuggerHidden] | ||
| 137 | 143 | public static bool IsNull(this in NewReference reference) | |
| 138 | 144 | => NewReference.IsNull(reference); | |
| 139 | 145 | ||
| 140 | 146 | ||
| 141 | 147 | [Pure] | |
| 148 | + [DebuggerHidden] | ||
| 142 | 149 | public static BorrowedReference BorrowNullable(this in NewReference reference) | |
| 143 | 150 | => new(NewReference.DangerousGetAddressOrNull(reference)); | |
| 144 | 151 | [Pure] | |
| 152 | + [DebuggerHidden] | ||
| 145 | 153 | public static BorrowedReference Borrow(this in NewReference reference) | |
| 146 | 154 | => reference.IsNull() ? throw new NullReferenceException() : reference.BorrowNullable(); | |
| 147 | 155 | [Pure] | |
@@ -150,6 +158,7 @@ public static BorrowedReference BorrowOrThrow(this in NewReference reference) | |||
| 150 | 158 | => reference.IsNull() ? throw PythonException.ThrowLastAsClrException() : reference.BorrowNullable(); | |
| 151 | 159 | ||
| 152 | 160 | [Obsolete] | |
| 161 | + [DebuggerHidden] | ||
| 153 | 162 | public static NewReference AnalyzerWorkaround(this in NewReference reference) | |
| 154 | 163 | => NewReference.DangerousFromPointer(reference.DangerousGetAddress()); | |
| 155 | 164 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | namespace Python.Runtime | |
| 2 | 2 | { | |
| 3 | 3 | using System; | |
| 4 | + using System.Diagnostics; | ||
| 4 | 5 | using System.Diagnostics.Contracts; | |
| 5 | 6 | using System.Runtime.CompilerServices; | |
| 6 | 7 | ||
@@ -13,6 +14,7 @@ readonly ref struct StolenReference | |||
| 13 | 14 | { | |
| 14 | 15 | internal readonly IntPtr Pointer; | |
| 15 | 16 | ||
| 17 | + [DebuggerHidden] | ||
| 16 | 18 | StolenReference(IntPtr pointer) | |
| 17 | 19 | { | |
| 18 | 20 | Pointer = pointer; | |
@@ -25,6 +27,7 @@ public static StolenReference Take(ref IntPtr ptr) | |||
| 25 | 27 | return TakeNullable(ref ptr); | |
| 26 | 28 | } | |
| 27 | 29 | [MethodImpl(MethodImplOptions.AggressiveInlining)] | |
| 30 | + [DebuggerHidden] | ||
| 28 | 31 | public static StolenReference TakeNullable(ref IntPtr ptr) | |
| 29 | 32 | { | |
| 30 | 33 | var stolenAddr = ptr; | |
@@ -62,12 +65,14 @@ public static StolenReference DangerousFromPointer(IntPtr ptr) | |||
| 62 | 65 | static class StolenReferenceExtensions | |
| 63 | 66 | { | |
| 64 | 67 | [Pure] | |
| 68 | + [DebuggerHidden] | ||
| 65 | 69 | public static IntPtr DangerousGetAddressOrNull(this in StolenReference reference) | |
| 66 | 70 | => reference.Pointer; | |
| 67 | 71 | [Pure] | |
| 72 | + [DebuggerHidden] | ||
| 68 | 73 | public static IntPtr DangerousGetAddress(this in StolenReference reference) | |
| 69 | 74 | => reference.Pointer == IntPtr.Zero ? throw new NullReferenceException() : reference.Pointer; | |
| 70 | - | ||
| 75 | + [DebuggerHidden] | ||
| 71 | 76 | public static StolenReference AnalyzerWorkaround(this in StolenReference reference) | |
| 72 | 77 | { | |
| 73 | 78 | IntPtr ptr = reference.DangerousGetAddressOrNull(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -155,6 +155,7 @@ static void SetupImportHook() | |||
| 155 | 155 | // Create the import hook module | |
| 156 | 156 | using var import_hook_module = Runtime.PyModule_New("clr.loader"); | |
| 157 | 157 | BorrowedReference mod_dict = Runtime.PyModule_GetDict(import_hook_module.BorrowOrThrow()); | |
| 158 | + Debug.Assert(mod_dict != null); | ||
| 158 | 159 | ||
| 159 | 160 | // Run the python code to create the module's classes. | |
| 160 | 161 | var builtins = Runtime.PyEval_GetBuiltins(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments