Skip to content

Commit

Permalink
implement PyDictMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Oct 20, 2023
1 parent 3aaa7e5 commit f46cc52
Show file tree
Hide file tree
Showing 3 changed files with 359 additions and 97 deletions.
11 changes: 11 additions & 0 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ impl<'py> Py2<'py, PyAny> {
) -> PyResult<Self> {
Py::from_owned_ptr_or_err(py, ptr).map(|obj| Self(py, ManuallyDrop::new(obj)))
}

/// Constructs a new Py2 from a borrowed pointer, incrementing the reference count.
/// Returns None if ptr is null.
///
/// Safety: ptr must be a valid pointer to a Python object, or NULL.
pub(crate) unsafe fn from_borrowed_ptr_or_opt(
py: Python<'py>,
ptr: *mut ffi::PyObject,
) -> Option<Self> {
Py::from_borrowed_ptr_or_opt(py, ptr).map(|obj| Self(py, ManuallyDrop::new(obj)))
}
}

impl<'py, T> Py2<'py, T> {
Expand Down
Loading

0 comments on commit f46cc52

Please sign in to comment.