# HG changeset patch # User Georges Racinet # Date 2024-12-07 17:05:47 # Node ID 64a618048ba857cb462eb066dc68bc28582640fc # Parent dd052842fc8ef09bd523a0fdd0eff0af08f07638 rust-pyo3: intermediate ProxyIndex extraction Retrieving the `UnsafePyLeaked` without borrowing it will be necessary for the upcoming classes that need to store an inner object derived from it. diff --git a/rust/hg-pyo3/src/convert_cpython.rs b/rust/hg-pyo3/src/convert_cpython.rs --- a/rust/hg-pyo3/src/convert_cpython.rs +++ b/rust/hg-pyo3/src/convert_cpython.rs @@ -166,17 +166,26 @@ pub fn py_rust_index_to_graph( Ok(unsafe { leaked.map(py, |idx| PySharedIndex { inner: &idx.index }) }) } +pub(crate) fn proxy_index_py_leak<'py>( + index_proxy: &Bound<'py, PyAny>, +) -> PyResult<(cpython::Python<'py>, cpython::UnsafePyLeaked)> { + let (py, idx_proxy) = to_cpython_py_object(index_proxy); + let py_leaked = py_rust_index_to_graph(py, idx_proxy)?; + Ok((py, py_leaked)) +} + /// Full extraction of the proxy index object as received in PyO3 to a /// [`CoreIndex`] reference. /// -/// The safety invariants to maintain are those of the underlying +/// # Safety +/// +/// The invariants to maintain are those of the underlying /// [`UnsafePyLeaked::try_borrow`]: the caller must not leak the inner /// reference. pub(crate) unsafe fn proxy_index_extract<'py>( index_proxy: &Bound<'py, PyAny>, ) -> PyResult<&'py CoreIndex> { - let (py, idx_proxy) = to_cpython_py_object(index_proxy); - let py_leaked = py_rust_index_to_graph(py, idx_proxy)?; + let (py, py_leaked) = proxy_index_py_leak(index_proxy)?; let py_shared = &*unsafe { py_leaked .try_borrow(py)