namespace Python.Runtime
{
using System;
///
/// Represents a reference to a Python object, that is being lent, and
/// can only be safely used until execution returns to the caller.
///
readonly ref struct BorrowedReference
{
readonly IntPtr pointer;
public bool IsNull => this.pointer == IntPtr.Zero;
/// Gets a raw pointer to the Python object
public IntPtr DangerousGetAddress()
=> this.IsNull ? throw new NullReferenceException() : this.pointer;
///
/// Creates new instance of from raw pointer. Unsafe.
///
public BorrowedReference(IntPtr pointer)
{
this.pointer = pointer;
}
}
}