(ptr: *mut Self)
| 1229 | /// (same guarantee as `_Py_TryIncRefShared`). |
| 1230 | #[inline] |
| 1231 | pub unsafe fn try_to_owned_from_ptr(ptr: *mut Self) -> Option<PyObjectRef> { |
| 1232 | let inner = ptr.cast::<PyInner<Erased>>(); |
| 1233 | let ref_count = unsafe { &*core::ptr::addr_of!((*inner).ref_count) }; |
| 1234 | if ref_count.safe_inc() { |
| 1235 | Some(PyObjectRef { |
| 1236 | ptr: unsafe { NonNull::new_unchecked(ptr) }, |
| 1237 | }) |
| 1238 | } else { |
| 1239 | None |
| 1240 | } |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | impl PyObjectRef { |