diff rust/hg-cpython/src/dirstate/dirs_multiset.rs @ 42850:8f549c46bc64

rust-cpython: pair leaked reference with its manager object Still leak_immutable() is unsafe since leak_handle must live longer than the leaked_ref.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 01 Sep 2019 17:48:24 +0900
parents 8db8fa1de2ef
children 64e28b891796
line wrap: on
line diff
--- a/rust/hg-cpython/src/dirstate/dirs_multiset.rs	Sun Sep 01 17:37:30 2019 +0900
+++ b/rust/hg-cpython/src/dirstate/dirs_multiset.rs	Sun Sep 01 17:48:24 2019 +0900
@@ -86,10 +86,11 @@
             })
     }
     def __iter__(&self) -> PyResult<DirsMultisetKeysIterator> {
+        let (leak_handle, leaked_ref) = self.leak_immutable(py)?;
         DirsMultisetKeysIterator::create_instance(
             py,
-            RefCell::new(Some(DirsMultisetLeakedRef::new(py, &self))),
-            RefCell::new(Box::new(self.leak_immutable(py)?.iter())),
+            RefCell::new(Some(leak_handle)),
+            RefCell::new(Box::new(leaked_ref.iter())),
         )
     }