Skip to content

Commit 42221c4

Browse files
committed
implement PyDictMethods
1 parent 9d75325 commit 42221c4

File tree

3 files changed

+360
-98
lines changed

3 files changed

+360
-98
lines changed

src/instance.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ impl<'py> Py2<'py, PyAny> {
6464
) -> PyResult<Self> {
6565
Py::from_owned_ptr_or_err(py, ptr).map(|obj| Self(py, ManuallyDrop::new(obj)))
6666
}
67+
68+
/// Constructs a new Py2 from a borrowed pointer, incrementing the reference count.
69+
/// Returns None if ptr is null.
70+
///
71+
/// Safety: ptr must be a valid pointer to a Python object, or NULL.
72+
pub(crate) unsafe fn from_borrowed_ptr_or_opt(
73+
py: Python<'py>,
74+
ptr: *mut ffi::PyObject,
75+
) -> Option<Self> {
76+
Py::from_borrowed_ptr_or_opt(py, ptr).map(|obj| Self(py, ManuallyDrop::new(obj)))
77+
}
6778
}
6879

6980
impl<'py, T> Py2<'py, T> {

0 commit comments

Comments
 (0)