|
1 | | -// TODO https://github.com/PyO3/pyo3/issues/5487 |
2 | | -#![allow(clippy::undocumented_unsafe_blocks)] |
3 | | - |
4 | 1 | use crate::sealed::Sealed; |
5 | 2 | use crate::{ |
6 | 3 | ffi, |
@@ -41,48 +38,80 @@ pub(crate) trait FfiPtrExt: Sealed { |
41 | 38 | } |
42 | 39 |
|
43 | 40 | impl FfiPtrExt for *mut ffi::PyObject { |
| 41 | + /// # Safety |
| 42 | + /// |
| 43 | + /// see requirements for [`Bound::from_owned_ptr_or_err`] |
44 | 44 | #[inline] |
45 | 45 | unsafe fn assume_owned_or_err(self, py: Python<'_>) -> PyResult<Bound<'_, PyAny>> { |
| 46 | + // SAFETY: caller upholds requirements |
46 | 47 | unsafe { Bound::from_owned_ptr_or_err(py, self) } |
47 | 48 | } |
48 | 49 |
|
| 50 | + /// # Safety |
| 51 | + /// |
| 52 | + /// see requirements for [`Bound::from_owned_ptr_or_opt`] |
49 | 53 | #[inline] |
50 | 54 | unsafe fn assume_owned_or_opt(self, py: Python<'_>) -> Option<Bound<'_, PyAny>> { |
| 55 | + // SAFETY: caller upholds requirements |
51 | 56 | unsafe { Bound::from_owned_ptr_or_opt(py, self) } |
52 | 57 | } |
53 | 58 |
|
| 59 | + /// # Safety |
| 60 | + /// |
| 61 | + /// see requirements for [`Bound::from_owned_ptr`] |
54 | 62 | #[inline] |
55 | 63 | #[track_caller] |
56 | 64 | unsafe fn assume_owned(self, py: Python<'_>) -> Bound<'_, PyAny> { |
| 65 | + // SAFETY: caller upholds requirements |
57 | 66 | unsafe { Bound::from_owned_ptr(py, self) } |
58 | 67 | } |
59 | 68 |
|
| 69 | + /// # Safety |
| 70 | + /// |
| 71 | + /// see requirements for [`Bound::from_owned_ptr_unchecked`] |
60 | 72 | #[inline] |
61 | 73 | unsafe fn assume_owned_unchecked(self, py: Python<'_>) -> Bound<'_, PyAny> { |
| 74 | + // SAFETY: caller upholds requirements |
62 | 75 | unsafe { Bound::from_owned_ptr_unchecked(py, self) } |
63 | 76 | } |
64 | 77 |
|
| 78 | + /// # Safety |
| 79 | + /// |
| 80 | + /// see requirements for [`Borrowed::from_ptr_or_err`] |
65 | 81 | #[inline] |
66 | 82 | unsafe fn assume_borrowed_or_err<'a>( |
67 | 83 | self, |
68 | 84 | py: Python<'_>, |
69 | 85 | ) -> PyResult<Borrowed<'a, '_, PyAny>> { |
| 86 | + // SAFETY: caller upholds requirements |
70 | 87 | unsafe { Borrowed::from_ptr_or_err(py, self) } |
71 | 88 | } |
72 | 89 |
|
| 90 | + /// # Safety |
| 91 | + /// |
| 92 | + /// see requirements for [`Borrowed::from_ptr_or_opt`] |
73 | 93 | #[inline] |
74 | 94 | unsafe fn assume_borrowed_or_opt<'a>(self, py: Python<'_>) -> Option<Borrowed<'a, '_, PyAny>> { |
| 95 | + // SAFETY: caller upholds requirements |
75 | 96 | unsafe { Borrowed::from_ptr_or_opt(py, self) } |
76 | 97 | } |
77 | 98 |
|
| 99 | + /// # Safety |
| 100 | + /// |
| 101 | + /// see requirements for [`Borrowed::from_ptr`] |
78 | 102 | #[inline] |
79 | 103 | #[track_caller] |
80 | 104 | unsafe fn assume_borrowed<'a>(self, py: Python<'_>) -> Borrowed<'a, '_, PyAny> { |
| 105 | + // SAFETY: caller upholds requirements |
81 | 106 | unsafe { Borrowed::from_ptr(py, self) } |
82 | 107 | } |
83 | 108 |
|
| 109 | + /// # Safety |
| 110 | + /// |
| 111 | + /// see requirements for [`Borrowed::from_ptr_unchecked`] |
84 | 112 | #[inline] |
85 | 113 | unsafe fn assume_borrowed_unchecked<'a>(self, py: Python<'_>) -> Borrowed<'a, '_, PyAny> { |
| 114 | + // SAFETY: caller upholds requirements |
86 | 115 | unsafe { Borrowed::from_ptr_unchecked(py, self) } |
87 | 116 | } |
88 | 117 | } |
0 commit comments