##// END OF EJS Templates
rust-cpython: remove useless PyRefMut wrapper
Yuya Nishihara -
r43610:75b4eb98 default
parent child Browse files
Show More
@@ -61,14 +61,14 b' impl PySharedState {'
61 &'a self,
61 &'a self,
62 py: Python<'a>,
62 py: Python<'a>,
63 pyrefmut: RefMut<'a, T>,
63 pyrefmut: RefMut<'a, T>,
64 ) -> PyResult<PyRefMut<'a, T>> {
64 ) -> PyResult<RefMut<'a, T>> {
65 match self.current_borrow_count(py) {
65 match self.current_borrow_count(py) {
66 0 => {
66 0 => {
67 // Note that this wraps around to the same value if mutably
67 // Note that this wraps around to the same value if mutably
68 // borrowed more than usize::MAX times, which wouldn't happen
68 // borrowed more than usize::MAX times, which wouldn't happen
69 // in practice.
69 // in practice.
70 self.generation.fetch_add(1, Ordering::Relaxed);
70 self.generation.fetch_add(1, Ordering::Relaxed);
71 Ok(PyRefMut::new(py, pyrefmut, self))
71 Ok(pyrefmut)
72 }
72 }
73 _ => Err(AlreadyBorrowed::new(
73 _ => Err(AlreadyBorrowed::new(
74 py,
74 py,
@@ -170,7 +170,7 b' impl<T> PySharedRefCell<T> {'
170 // inner.try_borrow_mut(). The current implementation panics if
170 // inner.try_borrow_mut(). The current implementation panics if
171 // self.inner has been borrowed, but returns error if py_shared_state
171 // self.inner has been borrowed, but returns error if py_shared_state
172 // refuses to borrow.
172 // refuses to borrow.
173 fn borrow_mut<'a>(&'a self, py: Python<'a>) -> PyResult<PyRefMut<'a, T>> {
173 fn borrow_mut<'a>(&'a self, py: Python<'a>) -> PyResult<RefMut<'a, T>> {
174 self.py_shared_state.borrow_mut(py, self.inner.borrow_mut())
174 self.py_shared_state.borrow_mut(py, self.inner.borrow_mut())
175 }
175 }
176 }
176 }
@@ -199,7 +199,7 b" impl<'a, T> PySharedRef<'a, T> {"
199 self.data.borrow(self.py)
199 self.data.borrow(self.py)
200 }
200 }
201
201
202 pub fn borrow_mut(&self) -> PyResult<PyRefMut<'a, T>> {
202 pub fn borrow_mut(&self) -> PyResult<RefMut<'a, T>> {
203 self.data.borrow_mut(self.py)
203 self.data.borrow_mut(self.py)
204 }
204 }
205
205
@@ -226,38 +226,6 b" impl<'a, T> PySharedRef<'a, T> {"
226 }
226 }
227 }
227 }
228
228
229 /// Holds a mutable reference to data shared between Python and Rust.
230 pub struct PyRefMut<'a, T> {
231 inner: RefMut<'a, T>,
232 }
233
234 impl<'a, T> PyRefMut<'a, T> {
235 // Must be constructed by PySharedState after checking its leak_count.
236 // Otherwise, drop() would incorrectly update the state.
237 fn new(
238 _py: Python<'a>,
239 inner: RefMut<'a, T>,
240 _py_shared_state: &'a PySharedState,
241 ) -> Self {
242 Self {
243 inner,
244 }
245 }
246 }
247
248 impl<'a, T> std::ops::Deref for PyRefMut<'a, T> {
249 type Target = RefMut<'a, T>;
250
251 fn deref(&self) -> &Self::Target {
252 &self.inner
253 }
254 }
255 impl<'a, T> std::ops::DerefMut for PyRefMut<'a, T> {
256 fn deref_mut(&mut self) -> &mut Self::Target {
257 &mut self.inner
258 }
259 }
260
261 /// Allows a `py_class!` generated struct to share references to one of its
229 /// Allows a `py_class!` generated struct to share references to one of its
262 /// data members with Python.
230 /// data members with Python.
263 ///
231 ///
General Comments 0
You need to be logged in to leave comments. Login now