Mercurial > hg
comparison rust/hg-cpython/src/dirstate/dirs_multiset.rs @ 43422:b9f791090211
rust-cpython: rename PyLeakedRef to PyLeaked
This series will make PyLeaked* behave more like a Python iterator, which
means mutation of the owner object will be allowed and the leaked reference
(i.e. the iterator) will be invalidated instead.
I'll add PyLeakedRef/PyLeakedRefMut structs which will represent a "borrowed"
state, and prevent the underlying value from being mutably borrowed while the
leaked reference is in use:
let shared = self.inner_shared(py);
let leaked = shared.leak_immutable();
{
let leaked_ref: PyLeakedRef<_> = leaked.borrow(py);
shared.borrow_mut(); // panics since the underlying value is borrowed
}
shared.borrow_mut(); // allowed
The relation between PyLeaked* structs is quite similar to RefCell/Ref/RefMut,
but the implementation can't be reused because the borrowing state will have
to be shared across objects having no lifetime relation.
PyLeaked isn't named as PyLeakedCell since it isn't actually a cell in that
leaked.borrow_mut() will require &mut self.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 12 Oct 2019 19:10:51 +0900 |
parents | f8c114f20d2d |
children | 8418b77132c1 |
comparison
equal
deleted
inserted
replaced
43305:d782cce137fd | 43422:b9f791090211 |
---|---|
15 exc, ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyObject, PyResult, | 15 exc, ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyObject, PyResult, |
16 Python, | 16 Python, |
17 }; | 17 }; |
18 | 18 |
19 use crate::dirstate::extract_dirstate; | 19 use crate::dirstate::extract_dirstate; |
20 use crate::ref_sharing::{PyLeakedRef, PySharedRefCell}; | 20 use crate::ref_sharing::{PyLeaked, PySharedRefCell}; |
21 use hg::{ | 21 use hg::{ |
22 utils::hg_path::{HgPath, HgPathBuf}, | 22 utils::hg_path::{HgPath, HgPathBuf}, |
23 DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError, | 23 DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError, |
24 EntryState, | 24 EntryState, |
25 }; | 25 }; |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 py_shared_iterator!( | 124 py_shared_iterator!( |
125 DirsMultisetKeysIterator, | 125 DirsMultisetKeysIterator, |
126 PyLeakedRef<DirsMultisetIter<'static>>, | 126 PyLeaked<DirsMultisetIter<'static>>, |
127 Dirs::translate_key, | 127 Dirs::translate_key, |
128 Option<PyBytes> | 128 Option<PyBytes> |
129 ); | 129 ); |