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

Skip to content

Commit d5fcfa4

Browse files
committed
fixup! More changes to use BorrowedReference and NewReference
1 parent cc6b8e4 commit d5fcfa4

File tree

3 files changed

+2
-23
lines changed

3 files changed

+2
-23
lines changed

src/runtime/BorrowedReference.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ readonly ref struct BorrowedReference
1010
readonly IntPtr pointer;
1111
public bool IsNull => this.pointer == IntPtr.Zero;
1212

13-
public static implicit operator IntPtr(in BorrowedReference self) => self.DangerousGetAddress();
1413

1514
/// <summary>Gets a raw pointer to the Python object</summary>
1615
public IntPtr DangerousGetAddress()

src/runtime/NewReference.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ ref struct NewReference
1515
public static implicit operator BorrowedReference(in NewReference reference)
1616
=> new BorrowedReference(reference.pointer);
1717

18-
[Pure]
19-
public static implicit operator IntPtr(in NewReference reference)
20-
=> DangerousGetAddress(reference);
21-
2218
/// <summary>
2319
/// Returns <see cref="PyObject"/> wrapper around this reference, which now owns
2420
/// the pointer. Sets the original reference to <c>null</c>, as it no longer owns it.

src/runtime/runtime.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -748,22 +748,6 @@ internal static IntPtr SelfIncRef(IntPtr op)
748748
return op;
749749
}
750750

751-
/// <remark>
752-
/// We need this method because BorrowedReference can be implicitly casted to IntPtr.
753-
/// </remark>
754-
internal static void XDecref(BorrowedReference op)
755-
{
756-
throw new InvalidOperationException("Cannot DecRef a borrowed reference.");
757-
}
758-
759-
/// <remark>
760-
/// We need this method because NewReference can be implicitly casted to IntPtr.
761-
/// </remark>
762-
internal static void XDecref(NewReference op)
763-
{
764-
op.Dispose();
765-
}
766-
767751
internal static unsafe void XDecref(IntPtr op)
768752
{
769753
#if PYTHON_WITH_PYDEBUG || NETSTANDARD
@@ -2148,10 +2132,10 @@ internal static void Py_CLEAR(ref IntPtr ob)
21482132
internal static extern NewReference PyCapsule_New(IntPtr pointer, string name, IntPtr destructor);
21492133

21502134
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
2151-
internal static extern IntPtr PyCapsule_GetPointer(IntPtr capsule, string name);
2135+
internal static extern IntPtr PyCapsule_GetPointer(BorrowedReference capsule, string name);
21522136

21532137
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
2154-
internal static extern int PyCapsule_SetPointer(IntPtr capsule, IntPtr pointer);
2138+
internal static extern int PyCapsule_SetPointer(BorrowedReference capsule, IntPtr pointer);
21552139

21562140
//====================================================================
21572141
// Miscellaneous

0 commit comments

Comments
 (0)