Mercurial > hg
diff rust/hg-cpython/src/dirstate/dirstate_map.rs @ 42851:64e28b891796
rust-cpython: mark unsafe functions as such
It wasn't trivial to fix leak_immutable() to be safe since we have to
allow immutable operations (e.g. iter()) on the leaked reference. So
let's mark it unsafe for now. Callers must take care of the returned
object to guarantee the memory safety.
I'll revisit this later. I think $leaked<T: 'static> could have a function
that converts itself into $leaked<U: 'static> with a given FnOnce(&T) -> &U,
where T is $inner_struct, and U is $iterator_type for example.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 01 Sep 2019 18:06:31 +0900 |
parents | 8f549c46bc64 |
children | 67853749961b |
line wrap: on
line diff
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs Sun Sep 01 17:48:24 2019 +0900 +++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs Sun Sep 01 18:06:31 2019 +0900 @@ -319,7 +319,7 @@ } def keys(&self) -> PyResult<DirstateMapKeysIterator> { - let (leak_handle, leaked_ref) = self.leak_immutable(py)?; + let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; DirstateMapKeysIterator::from_inner( py, Some(leak_handle), @@ -328,7 +328,7 @@ } def items(&self) -> PyResult<DirstateMapItemsIterator> { - let (leak_handle, leaked_ref) = self.leak_immutable(py)?; + let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; DirstateMapItemsIterator::from_inner( py, Some(leak_handle), @@ -337,7 +337,7 @@ } def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { - let (leak_handle, leaked_ref) = self.leak_immutable(py)?; + let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; DirstateMapKeysIterator::from_inner( py, Some(leak_handle), @@ -434,7 +434,7 @@ } def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { - let (leak_handle, leaked_ref) = self.leak_immutable(py)?; + let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; CopyMapKeysIterator::from_inner( py, Some(leak_handle), @@ -443,7 +443,7 @@ } def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { - let (leak_handle, leaked_ref) = self.leak_immutable(py)?; + let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; CopyMapItemsIterator::from_inner( py, Some(leak_handle),