From d5c886f4c055d4a1241d555a9b03811c44b13399 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Sun, 7 Jul 2024 07:53:43 +0100 Subject: [PATCH] simplify implementation of `Py::clone_ref` (#4313) --- src/instance.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/instance.rs b/src/instance.rs index 4703dd12a94..cc1ae684e44 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -1329,8 +1329,11 @@ impl Py { /// # } /// ``` #[inline] - pub fn clone_ref(&self, py: Python<'_>) -> Py { - unsafe { Py::from_borrowed_ptr(py, self.0.as_ptr()) } + pub fn clone_ref(&self, _py: Python<'_>) -> Py { + unsafe { + ffi::Py_INCREF(self.as_ptr()); + Self::from_non_null(self.0) + } } /// Drops `self` and immediately decreases its reference count.