| 1881 | /// Refcount is NOT incremented — ownership is transferred. |
| 1882 | #[inline(always)] |
| 1883 | pub fn new_owned(obj: PyObjectRef) -> Self { |
| 1884 | let ptr = obj.into_raw(); |
| 1885 | let bits = ptr.as_ptr() as usize; |
| 1886 | debug_assert!( |
| 1887 | bits & STACKREF_BORROW_TAG == 0, |
| 1888 | "PyObject pointer must be aligned" |
| 1889 | ); |
| 1890 | Self { |
| 1891 | // SAFETY: valid PyObject pointers are never null |
| 1892 | bits: unsafe { NonZeroUsize::new_unchecked(bits) }, |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | /// Create a borrowed stack reference from a `&PyObject`. |
| 1897 | /// |