comparison rust/hg-cpython/src/dirstate/dirstate_map.rs @ 44234:bad4e7b361d2

rust-cpython: switch to upstreamed version of PySharedRefCell Our PyLeaked is identical to cpython::UnsafePyLeaked. I've renamed it because it provides mostly unsafe functions.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 25 Jan 2020 17:26:23 +0900
parents 281642cd1d04
children cf1f8660e568
comparison
equal deleted inserted replaced
44233:281642cd1d04 44234:bad4e7b361d2
12 use std::convert::TryInto; 12 use std::convert::TryInto;
13 use std::time::Duration; 13 use std::time::Duration;
14 14
15 use cpython::{ 15 use cpython::{
16 exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyObject, 16 exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyObject,
17 PyResult, PyTuple, Python, PythonObject, ToPyObject, 17 PyResult, PyTuple, Python, PythonObject, ToPyObject, UnsafePyLeaked,
18 }; 18 };
19 19
20 use crate::{ 20 use crate::{
21 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, 21 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator},
22 dirstate::{dirs_multiset::Dirs, make_dirstate_tuple}, 22 dirstate::{dirs_multiset::Dirs, make_dirstate_tuple},
23 ref_sharing::{PyLeaked, PySharedRefCell},
24 }; 23 };
25 use hg::{ 24 use hg::{
26 utils::hg_path::{HgPath, HgPathBuf}, 25 utils::hg_path::{HgPath, HgPathBuf},
27 DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap, 26 DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap,
28 DirstateMapError, DirstateParents, DirstateParseError, EntryState, 27 DirstateMapError, DirstateParents, DirstateParseError, EntryState,
40 // `py_class!` is already implemented and does not mention 39 // `py_class!` is already implemented and does not mention
41 // `RustDirstateMap`, rightfully so. 40 // `RustDirstateMap`, rightfully so.
42 // All attributes also have to have a separate refcount data attribute for 41 // All attributes also have to have a separate refcount data attribute for
43 // leaks, with all methods that go along for reference sharing. 42 // leaks, with all methods that go along for reference sharing.
44 py_class!(pub class DirstateMap |py| { 43 py_class!(pub class DirstateMap |py| {
45 data inner_: PySharedRefCell<RustDirstateMap>; 44 @shared data inner: RustDirstateMap;
46 45
47 def __new__(_cls, _root: PyObject) -> PyResult<Self> { 46 def __new__(_cls, _root: PyObject) -> PyResult<Self> {
48 let inner = RustDirstateMap::default(); 47 let inner = RustDirstateMap::default();
49 Self::create_instance( 48 Self::create_instance(py, inner)
50 py,
51 PySharedRefCell::new(inner),
52 )
53 } 49 }
54 50
55 def clear(&self) -> PyResult<PyObject> { 51 def clear(&self) -> PyResult<PyObject> {
56 self.inner(py).borrow_mut().clear(); 52 self.inner(py).borrow_mut().clear();
57 Ok(py.None()) 53 Ok(py.None())
495 make_dirstate_tuple(py, entry)?, 491 make_dirstate_tuple(py, entry)?,
496 ))) 492 )))
497 } 493 }
498 } 494 }
499 495
500 py_shared_ref!(DirstateMap, RustDirstateMap, inner_, inner);
501
502 py_shared_iterator!( 496 py_shared_iterator!(
503 DirstateMapKeysIterator, 497 DirstateMapKeysIterator,
504 PyLeaked<StateMapIter<'static>>, 498 UnsafePyLeaked<StateMapIter<'static>>,
505 DirstateMap::translate_key, 499 DirstateMap::translate_key,
506 Option<PyBytes> 500 Option<PyBytes>
507 ); 501 );
508 502
509 py_shared_iterator!( 503 py_shared_iterator!(
510 DirstateMapItemsIterator, 504 DirstateMapItemsIterator,
511 PyLeaked<StateMapIter<'static>>, 505 UnsafePyLeaked<StateMapIter<'static>>,
512 DirstateMap::translate_key_value, 506 DirstateMap::translate_key_value,
513 Option<(PyBytes, PyObject)> 507 Option<(PyBytes, PyObject)>
514 ); 508 );
515 509
516 fn extract_node_id(py: Python, obj: &PyObject) -> PyResult<[u8; PARENT_SIZE]> { 510 fn extract_node_id(py: Python, obj: &PyObject) -> PyResult<[u8; PARENT_SIZE]> {