Mercurial > hg
diff rust/hg-cpython/src/dirstate/dirstate_map.rs @ 43284:ce6dd1cee4c8
rust-cpython: put leaked reference in PyLeakedRef
The next patch will make PyLeakedRef manage the lifetime of the underlying
object. leak_handle.data.take() will be removed soon.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 15 Sep 2019 22:06:19 +0900 |
parents | 478d0b1bf0c5 |
children | ffc1fbd7d1f5 |
line wrap: on
line diff
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs Thu Oct 17 20:40:12 2019 -0700 +++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs Sun Sep 15 22:06:19 2019 +0900 @@ -304,8 +304,9 @@ } def keys(&self) -> PyResult<DirstateMapKeysIterator> { - let (leak_handle, leaked_ref) = + let mut leak_handle = unsafe { self.inner_shared(py).leak_immutable()? }; + let leaked_ref = leak_handle.data.take().unwrap(); DirstateMapKeysIterator::from_inner( py, leak_handle, @@ -314,8 +315,9 @@ } def items(&self) -> PyResult<DirstateMapItemsIterator> { - let (leak_handle, leaked_ref) = + let mut leak_handle = unsafe { self.inner_shared(py).leak_immutable()? }; + let leaked_ref = leak_handle.data.take().unwrap(); DirstateMapItemsIterator::from_inner( py, leak_handle, @@ -324,8 +326,9 @@ } def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { - let (leak_handle, leaked_ref) = + let mut leak_handle = unsafe { self.inner_shared(py).leak_immutable()? }; + let leaked_ref = leak_handle.data.take().unwrap(); DirstateMapKeysIterator::from_inner( py, leak_handle, @@ -443,8 +446,9 @@ } def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { - let (leak_handle, leaked_ref) = + let mut leak_handle = unsafe { self.inner_shared(py).leak_immutable()? }; + let leaked_ref = leak_handle.data.take().unwrap(); CopyMapKeysIterator::from_inner( py, leak_handle, @@ -453,8 +457,9 @@ } def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { - let (leak_handle, leaked_ref) = + let mut leak_handle = unsafe { self.inner_shared(py).leak_immutable()? }; + let leaked_ref = leak_handle.data.take().unwrap(); CopyMapItemsIterator::from_inner( py, leak_handle, @@ -493,7 +498,7 @@ py_shared_iterator!( DirstateMapKeysIterator, - PyLeakedRef, + PyLeakedRef<&'static RustDirstateMap>, StateMapIter<'static>, DirstateMap::translate_key, Option<PyBytes> @@ -501,7 +506,7 @@ py_shared_iterator!( DirstateMapItemsIterator, - PyLeakedRef, + PyLeakedRef<&'static RustDirstateMap>, StateMapIter<'static>, DirstateMap::translate_key_value, Option<(PyBytes, PyObject)>