Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose Bound::from_owned_ptr etc #3779

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,33 +105,34 @@ where
}

impl<'py> Bound<'py, PyAny> {
/// Constructs a new Bound from a pointer. Panics if ptr is null.
/// Constructs a new `Bound<'py, PyAny>` from a pointer. Panics if `ptr` is null.
///
/// # Safety
///
/// `ptr` must be a valid pointer to a Python object.
pub(crate) unsafe fn from_owned_ptr(py: Python<'py>, ptr: *mut ffi::PyObject) -> Self {
/// - `ptr` must be a valid pointer to a Python object
/// - `ptr` must be an owned Python reference, as the `Bound<'py, PyAny>` will assume ownership
pub unsafe fn from_owned_ptr(py: Python<'py>, ptr: *mut ffi::PyObject) -> Self {
Self(py, ManuallyDrop::new(Py::from_owned_ptr(py, ptr)))
}

/// Constructs a new Bound from a pointer. Returns None if ptr is null.
/// Constructs a new `Bound<'py, PyAny>` from a pointer. Returns `None`` if `ptr` is null.
///
/// # Safety
///
/// `ptr` must be a valid pointer to a Python object, or NULL.
pub(crate) unsafe fn from_owned_ptr_or_opt(
py: Python<'py>,
ptr: *mut ffi::PyObject,
) -> Option<Self> {
/// - `ptr` must be a valid pointer to a Python object, or null
/// - `ptr` must be an owned Python reference, as the `Bound<'py, PyAny>` will assume ownership
pub unsafe fn from_owned_ptr_or_opt(py: Python<'py>, ptr: *mut ffi::PyObject) -> Option<Self> {
Py::from_owned_ptr_or_opt(py, ptr).map(|obj| Self(py, ManuallyDrop::new(obj)))
}

/// Constructs a new Bound from a pointer. Returns error if ptr is null.
/// Constructs a new `Bound<'py, PyAny>` from a pointer. Returns an `Err` by calling `PyErr::fetch`
/// if `ptr` is null.
///
/// # Safety
///
/// `ptr` must be a valid pointer to a Python object, or NULL.
pub(crate) unsafe fn from_owned_ptr_or_err(
/// - `ptr` must be a valid pointer to a Python object, or null
/// - `ptr` must be an owned Python reference, as the `Bound<'py, PyAny>` will assume ownership
pub unsafe fn from_owned_ptr_or_err(
py: Python<'py>,
ptr: *mut ffi::PyObject,
) -> PyResult<Self> {
Expand Down
Loading