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

Skip to content

Commit 2d11f82

Browse files
committed
make BorrowedReference readonly ref struct
1 parent e1ba92c commit 2d11f82

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/runtime/BorrowedReference.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace Python.Runtime
22
{
33
using System;
4-
ref struct BorrowedReference
4+
readonly ref struct BorrowedReference
55
{
6-
public IntPtr Pointer;
6+
public readonly IntPtr Pointer;
77
public bool IsNull => this.Pointer == IntPtr.Zero;
88

99
public PyObject ToPyObject()
@@ -13,13 +13,14 @@ public PyObject ToPyObject()
1313
Runtime.XIncref(this.Pointer);
1414
return new PyObject(this.Pointer);
1515
}
16-
}
1716

18-
static class BorrowedReferenceExtensions {
1917
[Obsolete("Use overloads, that take BorrowedReference or NewReference")]
20-
public static IntPtr DangerousGetAddress(this in BorrowedReference reference)
21-
=> reference.IsNull() ? throw new NullReferenceException() : reference.Pointer;
22-
public static bool IsNull(this in BorrowedReference reference)
23-
=> reference.Pointer == IntPtr.Zero;
18+
public IntPtr DangerousGetAddress()
19+
=> this.IsNull ? throw new NullReferenceException() : this.Pointer;
20+
21+
BorrowedReference(IntPtr pointer)
22+
{
23+
this.Pointer = pointer;
24+
}
2425
}
2526
}

0 commit comments

Comments
 (0)