##// END OF EJS Templates
rust-pyo3: generic borrows of UnsafePyLeaked with error treatment...
Georges Racinet -
r53427:73655156 default
parent child Browse files
Show More
@@ -213,6 +213,40 pub(crate) unsafe fn proxy_index_extract
213 Ok(py_shared.inner)
213 Ok(py_shared.inner)
214 }
214 }
215
215
216 /// Generic borrow of [`cpython::UnsafePyLeaked`], with proper mapping.
217 ///
218 /// # Safety
219 ///
220 /// The invariants to maintain are those of the underlying
221 /// [`UnsafePyLeaked::try_borrow`]: the caller must not leak the inner
222 /// static reference. It is possible, depending on `T` that such a leak cannot
223 /// occur in practice. We may later on define a marker trait for this,
224 /// which will allow us to make declare this function to be safe.
225 #[allow(dead_code)]
226 pub(crate) unsafe fn py_leaked_borrow<'a, 'py: 'a, T>(
227 py: &impl WithGIL<'py>,
228 leaked: &'a cpython::UnsafePyLeaked<T>,
229 ) -> PyResult<cpython::PyLeakedRef<'a, T>> {
230 let py = cpython_handle(py);
231 leaked.try_borrow(py).map_err(|e| from_cpython_pyerr(py, e))
232 }
233
234 /// Mutable variant of [`py_leaked_borrow`]
235 ///
236 /// # Safety
237 ///
238 /// See [`py_leaked_borrow`]
239 #[allow(dead_code)]
240 pub(crate) unsafe fn py_leaked_borrow_mut<'a, 'py: 'a, T>(
241 py: &impl WithGIL<'py>,
242 leaked: &'a mut cpython::UnsafePyLeaked<T>,
243 ) -> PyResult<cpython::PyLeakedRefMut<'a, T>> {
244 let py = cpython_handle(py);
245 leaked
246 .try_borrow_mut(py)
247 .map_err(|e| from_cpython_pyerr(py, e))
248 }
249
216 /// Error propagation for an [`UnsafePyLeaked`] wrapping a [`Result`]
250 /// Error propagation for an [`UnsafePyLeaked`] wrapping a [`Result`]
217 ///
251 ///
218 /// TODO (will consider when implementing UnsafePyLeaked in PyO3):
252 /// TODO (will consider when implementing UnsafePyLeaked in PyO3):
General Comments 0
You need to be logged in to leave comments. Login now