Mercurial > hg
diff rust/hg-cpython/src/dirstate/dirstate_map.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/dirstate_map.rs Sun Sep 01 17:37:30 2019 +0900 +++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs Sun Sep 01 17:48:24 2019 +0900 @@ -319,26 +319,29 @@ } def keys(&self) -> PyResult<DirstateMapKeysIterator> { + let (leak_handle, leaked_ref) = self.leak_immutable(py)?; DirstateMapKeysIterator::from_inner( py, - Some(DirstateMapLeakedRef::new(py, &self)), - Box::new(self.leak_immutable(py)?.iter()), + Some(leak_handle), + Box::new(leaked_ref.iter()), ) } def items(&self) -> PyResult<DirstateMapItemsIterator> { + let (leak_handle, leaked_ref) = self.leak_immutable(py)?; DirstateMapItemsIterator::from_inner( py, - Some(DirstateMapLeakedRef::new(py, &self)), - Box::new(self.leak_immutable(py)?.iter()), + Some(leak_handle), + Box::new(leaked_ref.iter()), ) } def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { + let (leak_handle, leaked_ref) = self.leak_immutable(py)?; DirstateMapKeysIterator::from_inner( py, - Some(DirstateMapLeakedRef::new(py, &self)), - Box::new(self.leak_immutable(py)?.iter()), + Some(leak_handle), + Box::new(leaked_ref.iter()), ) } @@ -431,18 +434,20 @@ } def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { + let (leak_handle, leaked_ref) = self.leak_immutable(py)?; CopyMapKeysIterator::from_inner( py, - Some(DirstateMapLeakedRef::new(py, &self)), - Box::new(self.leak_immutable(py)?.copy_map.iter()), + Some(leak_handle), + Box::new(leaked_ref.copy_map.iter()), ) } def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { + let (leak_handle, leaked_ref) = self.leak_immutable(py)?; CopyMapItemsIterator::from_inner( py, - Some(DirstateMapLeakedRef::new(py, &self)), - Box::new(self.leak_immutable(py)?.copy_map.iter()), + Some(leak_handle), + Box::new(leaked_ref.copy_map.iter()), ) }