##// END OF EJS Templates
rust-cpython: move borrow_mut() to PySharedRefCell...
Yuya Nishihara -
r43444:1c675c5f default
parent child Browse files
Show More
@@ -140,9 +140,15 b' impl<T> PySharedRefCell<T> {'
140 self.inner.as_ptr()
140 self.inner.as_ptr()
141 }
141 }
142
142
143 pub unsafe fn borrow_mut(&self) -> RefMut<T> {
143 // TODO: maybe this should be named as try_borrow_mut(), and use
144 // must be borrowed by self.py_shared_state(py).borrow_mut().
144 // inner.try_borrow_mut(). The current implementation panics if
145 self.inner.borrow_mut()
145 // self.inner has been borrowed, but returns error if py_shared_state
146 // refuses to borrow.
147 pub fn borrow_mut<'a>(
148 &'a self,
149 py: Python<'a>,
150 ) -> PyResult<PyRefMut<'a, T>> {
151 self.py_shared_state.borrow_mut(py, self.inner.borrow_mut())
146 }
152 }
147 }
153 }
148
154
@@ -231,6 +237,7 b' macro_rules! py_shared_ref {'
231 $leaked: ident,
237 $leaked: ident,
232 ) => {
238 ) => {
233 impl $name {
239 impl $name {
240 // TODO: remove this function in favor of inner(py).borrow_mut()
234 fn borrow_mut<'a>(
241 fn borrow_mut<'a>(
235 &'a self,
242 &'a self,
236 py: Python<'a>,
243 py: Python<'a>,
@@ -239,8 +246,7 b' macro_rules! py_shared_ref {'
239 // assert $data_member type
246 // assert $data_member type
240 use crate::ref_sharing::PySharedRefCell;
247 use crate::ref_sharing::PySharedRefCell;
241 let data: &PySharedRefCell<_> = self.$data_member(py);
248 let data: &PySharedRefCell<_> = self.$data_member(py);
242 data.py_shared_state
249 data.borrow_mut(py)
243 .borrow_mut(py, unsafe { data.borrow_mut() })
244 }
250 }
245
251
246 /// Returns a leaked reference and its management object.
252 /// Returns a leaked reference and its management object.
General Comments 0
You need to be logged in to leave comments. Login now