comparison rust/hg-cpython/src/ref_sharing.rs @ 43179:7d6758f2d50c

rust-cpython: drop self.leak_immutable() in favor of PySharedRef wrapper
author Yuya Nishihara <yuya@tcha.org>
date Sun, 15 Sep 2019 16:59:50 +0900
parents 1b2200bd06b6
children b3dda04e851b
comparison
equal deleted inserted replaced
43178:1b2200bd06b6 43179:7d6758f2d50c
317 py: Python<'a>, 317 py: Python<'a>,
318 ) -> PyResult<crate::ref_sharing::PyRefMut<'a, $inner_struct>> 318 ) -> PyResult<crate::ref_sharing::PyRefMut<'a, $inner_struct>>
319 { 319 {
320 self.$shared_accessor(py).borrow_mut() 320 self.$shared_accessor(py).borrow_mut()
321 } 321 }
322
323 // TODO: remove this function in favor of $shared_accessor(py)
324 unsafe fn leak_immutable<'a>(
325 &'a self,
326 py: Python<'a>,
327 ) -> PyResult<(PyLeakedRef, &'static $inner_struct)> {
328 self.$shared_accessor(py).leak_immutable()
329 }
330 } 322 }
331 }; 323 };
332 } 324 }
333 325
334 /// Manage immutable references to `PyObject` leaked into Python iterators. 326 /// Manage immutable references to `PyObject` leaked into Python iterators.
394 /// 386 ///
395 /// py_class!(pub class MyType |py| { 387 /// py_class!(pub class MyType |py| {
396 /// data inner: PySharedRefCell<MyStruct>; 388 /// data inner: PySharedRefCell<MyStruct>;
397 /// 389 ///
398 /// def __iter__(&self) -> PyResult<MyTypeItemsIterator> { 390 /// def __iter__(&self) -> PyResult<MyTypeItemsIterator> {
399 /// let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; 391 /// let (leak_handle, leaked_ref) =
392 /// unsafe { self.inner_shared(py).leak_immutable()? };
400 /// MyTypeItemsIterator::from_inner( 393 /// MyTypeItemsIterator::from_inner(
401 /// py, 394 /// py,
402 /// leak_handle, 395 /// leak_handle,
403 /// leaked_ref.iter(), 396 /// leaked_ref.iter(),
404 /// ) 397 /// )