##// END OF EJS Templates
rust-cpython: remove useless wrappers from PyLeaked, just move by map()...
Yuya Nishihara -
r44649:1f9e6fbd default
parent child Browse files
Show More
@@ -283,7 +283,7 b' macro_rules! py_shared_ref {'
283 283 /// borrowed.
284 284 pub struct PyLeaked<T> {
285 285 inner: PyObject,
286 data: Option<T>,
286 data: T,
287 287 py_shared_state: &'static PySharedState,
288 288 /// Generation counter of data `T` captured when PyLeaked is created.
289 289 generation: usize,
@@ -305,7 +305,7 b' impl<T> PyLeaked<T> {'
305 305 ) -> Self {
306 306 Self {
307 307 inner: inner.clone_ref(py),
308 data: Some(data),
308 data: data,
309 309 py_shared_state,
310 310 generation: py_shared_state.current_generation(py),
311 311 }
@@ -321,7 +321,7 b' impl<T> PyLeaked<T> {'
321 321 self.validate_generation(py)?;
322 322 Ok(PyLeakedRef {
323 323 _borrow: BorrowPyShared::new(py, self.py_shared_state),
324 data: self.data.as_ref().unwrap(),
324 data: &self.data,
325 325 })
326 326 }
327 327
@@ -338,7 +338,7 b' impl<T> PyLeaked<T> {'
338 338 self.validate_generation(py)?;
339 339 Ok(PyLeakedRefMut {
340 340 _borrow: BorrowPyShared::new(py, self.py_shared_state),
341 data: self.data.as_mut().unwrap(),
341 data: &mut self.data,
342 342 })
343 343 }
344 344
@@ -361,7 +361,7 b' impl<T> PyLeaked<T> {'
361 361 /// corresponding `PyLeaked` is alive. Do not copy it out of the
362 362 /// function call.
363 363 pub unsafe fn map<U>(
364 mut self,
364 self,
365 365 py: Python,
366 366 f: impl FnOnce(T) -> U,
367 367 ) -> PyLeaked<U> {
@@ -374,10 +374,10 b' impl<T> PyLeaked<T> {'
374 374 // In order to make this function safe, maybe we'll need a way to
375 375 // temporarily restrict the lifetime of self.data and translate the
376 376 // returned object back to Something<'static>.
377 let new_data = f(self.data.take().unwrap());
377 let new_data = f(self.data);
378 378 PyLeaked {
379 inner: self.inner.clone_ref(py),
380 data: Some(new_data),
379 inner: self.inner,
380 data: new_data,
381 381 py_shared_state: self.py_shared_state,
382 382 generation: self.generation,
383 383 }
General Comments 0
You need to be logged in to leave comments. Login now