8000 a few annotation to ease debugging · pythonnet/pythonnet@d0a6f44 · GitHub
[go: up one dir, main page]

Skip to content

Commit d0a6f44

Browse files
committed
a few annotation to ease debugging
1 parent e003e12 commit d0a6f44

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

src/runtime/BorrowedReference.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
namespace Python.Runtime
22
{
33
using System;
4+
using System.Diagnostics;
5+
46
/// <summary>
57
/// Represents a reference to a Python object, that is being lent, and
68
/// can only be safely used until execution returns to the caller.
@@ -11,6 +13,7 @@ readonly ref struct BorrowedReference
1113
public bool IsNull => this.pointer == IntPtr.Zero;
1214

1315
/// <summary>Gets a raw pointer to the Python object</summary>
16+
[DebuggerHidden]
1417
public IntPtr DangerousGetAddress()
1518
=> this.IsNull ? throw new NullReferenceException() : this.pointer;
1619
/// <summary>Gets a raw pointer to the Python object</summary>

src/runtime/NewReference.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ref struct NewReference
1414
IntPtr pointer;
1515

1616
/// <summary>Creates a <see cref="NewReference"/> pointing to the same object</summary>
17+
[DebuggerHidden]
1718
public NewReference(BorrowedReference reference, bool canBeNull = false)
1819
{
1920
var address = canBeNull
@@ -69,13 +70,15 @@ public IntPtr DangerousMoveToPointerOrNull()
6970
/// that steals reference passed to it.
7071
/// </summary>
7172
[MethodImpl(MethodImplOptions.AggressiveInlining)]
73+
[DebuggerHidden]
7274
public StolenReference StealNullable() => StolenReference.TakeNullable(ref this.pointer);
7375

7476
/// <summary>
7577
/// Call this method to move ownership of this reference to a Python C API function,
7678
/// that steals reference passed to it.
7779
/// </summary>
7880
[MethodImpl(MethodImplOptions.AggressiveInlining)]
81+
[DebuggerHidden]
7982
public StolenReference Steal()
8083
{
8184
if (this.IsNull()) throw new NullReferenceException();
@@ -118,6 +121,7 @@ public static NewReference DangerousFromPointer(IntPtr pointer)
118121
internal static IntPtr DangerousGetAddress(in NewReference reference)
119122
=> IsNull(reference) ? throw new NullReferenceException() : reference.pointer;
120123
[Pure]
124+
[DebuggerHidden]
121125
internal static bool IsNull(in NewReference reference)
122126
=> reference.pointer == IntPtr.Zero;
123127
}
@@ -131,17 +135,21 @@ static class NewReferenceExtensions
131135
{
132136
/// <summary>Gets a raw pointer to the Python object</summary>
133137
[Pure]
138+
[DebuggerHidden]
134139
public static IntPtr DangerousGetAddress(this in NewReference reference)
135140
=> NewReference.DangerousGetAddress(reference);
136141
[Pure]
142+
[DebuggerHidden]
137143
public static bool IsNull(this in NewReference reference)
138144
=> NewReference.IsNull(reference);
139145

140146

141147
[Pure]
148+
[DebuggerHidden]
142149
public static BorrowedReference BorrowNullable(this in NewReference reference)
143150
=> new(NewReference.DangerousGetAddressOrNull(reference));
144151
[Pure]
152+
[DebuggerHidden]
145153
public static BorrowedReference Borrow(this in NewReference reference)
146154
=> reference.IsNull() ? throw new NullReferenceException() : reference.BorrowNullable();
147155
[Pure]
@@ -150,6 +158,7 @@ public static BorrowedReference BorrowOrThrow(this in NewReference reference)
150158
=> reference.IsNull() ? throw PythonException.ThrowLastAsClrException() : reference.BorrowNullable();
151159

152160
[Obsolete]
161+
[DebuggerHidden]
153162
public static NewReference AnalyzerWorkaround(this in NewReference reference)
154163
=> NewReference.DangerousFromPointer(reference.DangerousGetAddress());
155164
}

src/runtime/StolenReference.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Python.Runtime
22
{
33
using System;
4+
using System.Diagnostics;
45
using System.Diagnostics.Contracts;
56
using System.Runtime.CompilerServices;
67

@@ -13,6 +14,7 @@ readonly ref s 67F4 truct StolenReference
1314
{
1415
internal readonly IntPtr Pointer;
1516

17+
[DebuggerHidden]
1618
StolenReference(IntPtr pointer)
1719
{
1820
Pointer = pointer;
@@ -25,6 +27,7 @@ public static StolenReference Take(ref IntPtr ptr)
2527
return TakeNullable(ref ptr);
2628
}
2729
[MethodImpl(MethodImplOptions.AggressiveInlining)]
30+
[DebuggerHidden]
2831
public static StolenReference TakeNullable(ref IntPtr ptr)
2932
{
3033
var stolenAddr = ptr;
@@ -62,12 +65,14 @@ public static StolenReference DangerousFromPointer(IntPtr ptr)
6265
static class StolenReferenceExtensions
6366
{
6467
[Pure]
68+
[DebuggerHidden]
6569
public static IntPtr DangerousGetAddressOrNull(this in StolenReference reference)
6670
=> reference.Pointer;
6771
[Pure]
72+
[DebuggerHidden]
6873
public static IntPtr DangerousGetAddress(this in StolenReference reference)
6974
=> reference.Pointer == IntPtr.Zero ? throw new NullReferenceException() : reference.Pointer;
70-
75+
[DebuggerHidden]
7176
public static StolenReference AnalyzerWorkaround(this in StolenReference reference)
7277
{
7378
IntPtr ptr = reference.DangerousGetAddressOrNull();

src/runtime/importhook.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ static void SetupImportHook()
155155
// Create the import hook module
156156
using var import_hook_module = Runtime.PyModule_New("clr.loader");
157157
BorrowedReference mod_dict = Runtime.PyModule_GetDict(import_hook_module.BorrowOrThrow());
158+
Debug.Assert(mod_dict != null);
158159

159160
// Run the python code to create the module's classes.
160161
var builtins = Runtime.PyEval_GetBuiltins();

0 commit comments

Comments
 (0)
0