##// END OF EJS Templates
rust-cpython: switch to upstreamed version of PySharedRefCell...
Yuya Nishihara -
r44703:bad4e7b3 default
parent child Browse files
Show More
@@ -8,11 +8,12 b''
8 //! Bindings for `hg::dirstate::dirstate_map::CopyMap` provided by the
8 //! Bindings for `hg::dirstate::dirstate_map::CopyMap` provided by the
9 //! `hg-core` package.
9 //! `hg-core` package.
10
10
11 use cpython::{PyBytes, PyClone, PyDict, PyObject, PyResult, Python};
11 use cpython::{
12 PyBytes, PyClone, PyDict, PyObject, PyResult, Python, UnsafePyLeaked,
13 };
12 use std::cell::RefCell;
14 use std::cell::RefCell;
13
15
14 use crate::dirstate::dirstate_map::DirstateMap;
16 use crate::dirstate::dirstate_map::DirstateMap;
15 use crate::ref_sharing::PyLeaked;
16 use hg::{utils::hg_path::HgPathBuf, CopyMapIter};
17 use hg::{utils::hg_path::HgPathBuf, CopyMapIter};
17
18
18 py_class!(pub class CopyMap |py| {
19 py_class!(pub class CopyMap |py| {
@@ -104,14 +105,14 b' impl CopyMap {'
104
105
105 py_shared_iterator!(
106 py_shared_iterator!(
106 CopyMapKeysIterator,
107 CopyMapKeysIterator,
107 PyLeaked<CopyMapIter<'static>>,
108 UnsafePyLeaked<CopyMapIter<'static>>,
108 CopyMap::translate_key,
109 CopyMap::translate_key,
109 Option<PyBytes>
110 Option<PyBytes>
110 );
111 );
111
112
112 py_shared_iterator!(
113 py_shared_iterator!(
113 CopyMapItemsIterator,
114 CopyMapItemsIterator,
114 PyLeaked<CopyMapIter<'static>>,
115 UnsafePyLeaked<CopyMapIter<'static>>,
115 CopyMap::translate_key_value,
116 CopyMap::translate_key_value,
116 Option<(PyBytes, PyBytes)>
117 Option<(PyBytes, PyBytes)>
117 );
118 );
@@ -13,11 +13,10 b' use std::convert::TryInto;'
13
13
14 use cpython::{
14 use cpython::{
15 exc, ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyObject, PyResult,
15 exc, ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyObject, PyResult,
16 Python,
16 Python, UnsafePyLeaked,
17 };
17 };
18
18
19 use crate::dirstate::extract_dirstate;
19 use crate::dirstate::extract_dirstate;
20 use crate::ref_sharing::{PyLeaked, PySharedRefCell};
21 use hg::{
20 use hg::{
22 utils::hg_path::{HgPath, HgPathBuf},
21 utils::hg_path::{HgPath, HgPathBuf},
23 DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError,
22 DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError,
@@ -25,7 +24,7 b' use hg::{'
25 };
24 };
26
25
27 py_class!(pub class Dirs |py| {
26 py_class!(pub class Dirs |py| {
28 data inner_: PySharedRefCell<DirsMultiset>;
27 @shared data inner: DirsMultiset;
29
28
30 // `map` is either a `dict` or a flat iterator (usually a `set`, sometimes
29 // `map` is either a `dict` or a flat iterator (usually a `set`, sometimes
31 // a `list`)
30 // a `list`)
@@ -65,10 +64,7 b' py_class!(pub class Dirs |py| {'
65 })?
64 })?
66 };
65 };
67
66
68 Self::create_instance(
67 Self::create_instance(py, inner)
69 py,
70 PySharedRefCell::new(inner),
71 )
72 }
68 }
73
69
74 def addpath(&self, path: PyObject) -> PyResult<PyObject> {
70 def addpath(&self, path: PyObject) -> PyResult<PyObject> {
@@ -123,11 +119,9 b' py_class!(pub class Dirs |py| {'
123 }
119 }
124 });
120 });
125
121
126 py_shared_ref!(Dirs, DirsMultiset, inner_, inner);
127
128 impl Dirs {
122 impl Dirs {
129 pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> {
123 pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> {
130 Self::create_instance(py, PySharedRefCell::new(d))
124 Self::create_instance(py, d)
131 }
125 }
132
126
133 fn translate_key(
127 fn translate_key(
@@ -140,7 +134,7 b' impl Dirs {'
140
134
141 py_shared_iterator!(
135 py_shared_iterator!(
142 DirsMultisetKeysIterator,
136 DirsMultisetKeysIterator,
143 PyLeaked<DirsMultisetIter<'static>>,
137 UnsafePyLeaked<DirsMultisetIter<'static>>,
144 Dirs::translate_key,
138 Dirs::translate_key,
145 Option<PyBytes>
139 Option<PyBytes>
146 );
140 );
@@ -14,13 +14,12 b' 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},
@@ -42,14 +41,11 b' use hg::{'
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> {
@@ -497,18 +493,16 b' impl DirstateMap {'
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 );
General Comments 0
You need to be logged in to leave comments. Login now