##// END OF EJS Templates
rust-cpython: require GIL to borrow immutable reference from PySharedRefCell...
Yuya Nishihara -
r43580:f8c114f2 default
parent child Browse files
Show More
@@ -100,7 +100,7 b' py_class!(pub class Dirs |py| {'
100 }
100 }
101
101
102 def __contains__(&self, item: PyObject) -> PyResult<bool> {
102 def __contains__(&self, item: PyObject) -> PyResult<bool> {
103 Ok(self.inner(py).borrow().contains(HgPath::new(
103 Ok(self.inner_shared(py).borrow().contains(HgPath::new(
104 item.extract::<PyBytes>(py)?.data(py).as_ref(),
104 item.extract::<PyBytes>(py)?.data(py).as_ref(),
105 )))
105 )))
106 }
106 }
@@ -63,7 +63,7 b' py_class!(pub class DirstateMap |py| {'
63 default: Option<PyObject> = None
63 default: Option<PyObject> = None
64 ) -> PyResult<Option<PyObject>> {
64 ) -> PyResult<Option<PyObject>> {
65 let key = key.extract::<PyBytes>(py)?;
65 let key = key.extract::<PyBytes>(py)?;
66 match self.inner(py).borrow().get(HgPath::new(key.data(py))) {
66 match self.inner_shared(py).borrow().get(HgPath::new(key.data(py))) {
67 Some(entry) => {
67 Some(entry) => {
68 Ok(Some(make_dirstate_tuple(py, entry)?))
68 Ok(Some(make_dirstate_tuple(py, entry)?))
69 },
69 },
@@ -170,7 +170,7 b' py_class!(pub class DirstateMap |py| {'
170 // TODO share the reference
170 // TODO share the reference
171 def nonnormalentries(&self) -> PyResult<PyObject> {
171 def nonnormalentries(&self) -> PyResult<PyObject> {
172 let (non_normal, other_parent) =
172 let (non_normal, other_parent) =
173 self.inner(py).borrow().non_normal_other_parent_entries();
173 self.inner_shared(py).borrow().non_normal_other_parent_entries();
174
174
175 let locals = PyDict::new(py);
175 let locals = PyDict::new(py);
176 locals.set_item(
176 locals.set_item(
@@ -281,18 +281,18 b' py_class!(pub class DirstateMap |py| {'
281 }
281 }
282
282
283 def __len__(&self) -> PyResult<usize> {
283 def __len__(&self) -> PyResult<usize> {
284 Ok(self.inner(py).borrow().len())
284 Ok(self.inner_shared(py).borrow().len())
285 }
285 }
286
286
287 def __contains__(&self, key: PyObject) -> PyResult<bool> {
287 def __contains__(&self, key: PyObject) -> PyResult<bool> {
288 let key = key.extract::<PyBytes>(py)?;
288 let key = key.extract::<PyBytes>(py)?;
289 Ok(self.inner(py).borrow().contains_key(HgPath::new(key.data(py))))
289 Ok(self.inner_shared(py).borrow().contains_key(HgPath::new(key.data(py))))
290 }
290 }
291
291
292 def __getitem__(&self, key: PyObject) -> PyResult<PyObject> {
292 def __getitem__(&self, key: PyObject) -> PyResult<PyObject> {
293 let key = key.extract::<PyBytes>(py)?;
293 let key = key.extract::<PyBytes>(py)?;
294 let key = HgPath::new(key.data(py));
294 let key = HgPath::new(key.data(py));
295 match self.inner(py).borrow().get(key) {
295 match self.inner_shared(py).borrow().get(key) {
296 Some(entry) => {
296 Some(entry) => {
297 Ok(make_dirstate_tuple(py, entry)?)
297 Ok(make_dirstate_tuple(py, entry)?)
298 },
298 },
@@ -333,7 +333,7 b' py_class!(pub class DirstateMap |py| {'
333 Dirs::from_inner(
333 Dirs::from_inner(
334 py,
334 py,
335 DirsMultiset::from_dirstate(
335 DirsMultiset::from_dirstate(
336 &self.inner(py).borrow(),
336 &self.inner_shared(py).borrow(),
337 Some(EntryState::Removed),
337 Some(EntryState::Removed),
338 ),
338 ),
339 )
339 )
@@ -344,7 +344,7 b' py_class!(pub class DirstateMap |py| {'
344 Dirs::from_inner(
344 Dirs::from_inner(
345 py,
345 py,
346 DirsMultiset::from_dirstate(
346 DirsMultiset::from_dirstate(
347 &self.inner(py).borrow(),
347 &self.inner_shared(py).borrow(),
348 None,
348 None,
349 ),
349 ),
350 )
350 )
@@ -353,7 +353,7 b' py_class!(pub class DirstateMap |py| {'
353 // TODO all copymap* methods, see docstring above
353 // TODO all copymap* methods, see docstring above
354 def copymapcopy(&self) -> PyResult<PyDict> {
354 def copymapcopy(&self) -> PyResult<PyDict> {
355 let dict = PyDict::new(py);
355 let dict = PyDict::new(py);
356 for (key, value) in self.inner(py).borrow().copy_map.iter() {
356 for (key, value) in self.inner_shared(py).borrow().copy_map.iter() {
357 dict.set_item(
357 dict.set_item(
358 py,
358 py,
359 PyBytes::new(py, key.as_ref()),
359 PyBytes::new(py, key.as_ref()),
@@ -365,7 +365,7 b' py_class!(pub class DirstateMap |py| {'
365
365
366 def copymapgetitem(&self, key: PyObject) -> PyResult<PyBytes> {
366 def copymapgetitem(&self, key: PyObject) -> PyResult<PyBytes> {
367 let key = key.extract::<PyBytes>(py)?;
367 let key = key.extract::<PyBytes>(py)?;
368 match self.inner(py).borrow().copy_map.get(HgPath::new(key.data(py))) {
368 match self.inner_shared(py).borrow().copy_map.get(HgPath::new(key.data(py))) {
369 Some(copy) => Ok(PyBytes::new(py, copy.as_ref())),
369 Some(copy) => Ok(PyBytes::new(py, copy.as_ref())),
370 None => Err(PyErr::new::<exc::KeyError, _>(
370 None => Err(PyErr::new::<exc::KeyError, _>(
371 py,
371 py,
@@ -378,12 +378,12 b' py_class!(pub class DirstateMap |py| {'
378 }
378 }
379
379
380 def copymaplen(&self) -> PyResult<usize> {
380 def copymaplen(&self) -> PyResult<usize> {
381 Ok(self.inner(py).borrow().copy_map.len())
381 Ok(self.inner_shared(py).borrow().copy_map.len())
382 }
382 }
383 def copymapcontains(&self, key: PyObject) -> PyResult<bool> {
383 def copymapcontains(&self, key: PyObject) -> PyResult<bool> {
384 let key = key.extract::<PyBytes>(py)?;
384 let key = key.extract::<PyBytes>(py)?;
385 Ok(self
385 Ok(self
386 .inner(py)
386 .inner_shared(py)
387 .borrow()
387 .borrow()
388 .copy_map
388 .copy_map
389 .contains_key(HgPath::new(key.data(py))))
389 .contains_key(HgPath::new(key.data(py))))
@@ -395,7 +395,7 b' py_class!(pub class DirstateMap |py| {'
395 ) -> PyResult<Option<PyObject>> {
395 ) -> PyResult<Option<PyObject>> {
396 let key = key.extract::<PyBytes>(py)?;
396 let key = key.extract::<PyBytes>(py)?;
397 match self
397 match self
398 .inner(py)
398 .inner_shared(py)
399 .borrow()
399 .borrow()
400 .copy_map
400 .copy_map
401 .get(HgPath::new(key.data(py)))
401 .get(HgPath::new(key.data(py)))
@@ -136,7 +136,7 b' impl<T> PySharedRefCell<T> {'
136 }
136 }
137 }
137 }
138
138
139 pub fn borrow(&self) -> Ref<T> {
139 pub fn borrow<'a>(&'a self, _py: Python<'a>) -> Ref<'a, T> {
140 // py_shared_state isn't involved since
140 // py_shared_state isn't involved since
141 // - inner.borrow() would fail if self is mutably borrowed,
141 // - inner.borrow() would fail if self is mutably borrowed,
142 // - and inner.borrow_mut() would fail while self is borrowed.
142 // - and inner.borrow_mut() would fail while self is borrowed.
@@ -180,7 +180,7 b" impl<'a, T> PySharedRef<'a, T> {"
180 }
180 }
181
181
182 pub fn borrow(&self) -> Ref<'a, T> {
182 pub fn borrow(&self) -> Ref<'a, T> {
183 self.data.borrow()
183 self.data.borrow(self.py)
184 }
184 }
185
185
186 pub fn borrow_mut(&self) -> PyResult<PyRefMut<'a, T>> {
186 pub fn borrow_mut(&self) -> PyResult<PyRefMut<'a, T>> {
General Comments 0
You need to be logged in to leave comments. Login now