##// END OF EJS Templates
rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara -
r43450:b3dda04e default
parent child Browse files
Show More
@@ -66,14 +66,14 b' py_class!(pub class Dirs |py| {'
66 }
66 }
67
67
68 def addpath(&self, path: PyObject) -> PyResult<PyObject> {
68 def addpath(&self, path: PyObject) -> PyResult<PyObject> {
69 self.borrow_mut(py)?.add_path(
69 self.inner_shared(py).borrow_mut()?.add_path(
70 HgPath::new(path.extract::<PyBytes>(py)?.data(py)),
70 HgPath::new(path.extract::<PyBytes>(py)?.data(py)),
71 );
71 );
72 Ok(py.None())
72 Ok(py.None())
73 }
73 }
74
74
75 def delpath(&self, path: PyObject) -> PyResult<PyObject> {
75 def delpath(&self, path: PyObject) -> PyResult<PyObject> {
76 self.borrow_mut(py)?.delete_path(
76 self.inner_shared(py).borrow_mut()?.delete_path(
77 HgPath::new(path.extract::<PyBytes>(py)?.data(py)),
77 HgPath::new(path.extract::<PyBytes>(py)?.data(py)),
78 )
78 )
79 .and(Ok(py.None()))
79 .and(Ok(py.None()))
@@ -54,7 +54,7 b' py_class!(pub class DirstateMap |py| {'
54 }
54 }
55
55
56 def clear(&self) -> PyResult<PyObject> {
56 def clear(&self) -> PyResult<PyObject> {
57 self.borrow_mut(py)?.clear();
57 self.inner_shared(py).borrow_mut()?.clear();
58 Ok(py.None())
58 Ok(py.None())
59 }
59 }
60
60
@@ -89,7 +89,7 b' py_class!(pub class DirstateMap |py| {'
89 size: PyObject,
89 size: PyObject,
90 mtime: PyObject
90 mtime: PyObject
91 ) -> PyResult<PyObject> {
91 ) -> PyResult<PyObject> {
92 self.borrow_mut(py)?.add_file(
92 self.inner_shared(py).borrow_mut()?.add_file(
93 HgPath::new(f.extract::<PyBytes>(py)?.data(py)),
93 HgPath::new(f.extract::<PyBytes>(py)?.data(py)),
94 oldstate.extract::<PyBytes>(py)?.data(py)[0]
94 oldstate.extract::<PyBytes>(py)?.data(py)[0]
95 .try_into()
95 .try_into()
@@ -116,7 +116,7 b' py_class!(pub class DirstateMap |py| {'
116 oldstate: PyObject,
116 oldstate: PyObject,
117 size: PyObject
117 size: PyObject
118 ) -> PyResult<PyObject> {
118 ) -> PyResult<PyObject> {
119 self.borrow_mut(py)?
119 self.inner_shared(py).borrow_mut()?
120 .remove_file(
120 .remove_file(
121 HgPath::new(f.extract::<PyBytes>(py)?.data(py)),
121 HgPath::new(f.extract::<PyBytes>(py)?.data(py)),
122 oldstate.extract::<PyBytes>(py)?.data(py)[0]
122 oldstate.extract::<PyBytes>(py)?.data(py)[0]
@@ -140,7 +140,7 b' py_class!(pub class DirstateMap |py| {'
140 f: PyObject,
140 f: PyObject,
141 oldstate: PyObject
141 oldstate: PyObject
142 ) -> PyResult<PyBool> {
142 ) -> PyResult<PyBool> {
143 self.borrow_mut(py)?
143 self.inner_shared(py).borrow_mut()?
144 .drop_file(
144 .drop_file(
145 HgPath::new(f.extract::<PyBytes>(py)?.data(py)),
145 HgPath::new(f.extract::<PyBytes>(py)?.data(py)),
146 oldstate.extract::<PyBytes>(py)?.data(py)[0]
146 oldstate.extract::<PyBytes>(py)?.data(py)[0]
@@ -171,7 +171,7 b' py_class!(pub class DirstateMap |py| {'
171 ))
171 ))
172 })
172 })
173 .collect();
173 .collect();
174 self.borrow_mut(py)?
174 self.inner_shared(py).borrow_mut()?
175 .clear_ambiguous_times(files?, now.extract(py)?);
175 .clear_ambiguous_times(files?, now.extract(py)?);
176 Ok(py.None())
176 Ok(py.None())
177 }
177 }
@@ -206,20 +206,20 b' py_class!(pub class DirstateMap |py| {'
206
206
207 def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> {
207 def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> {
208 let d = d.extract::<PyBytes>(py)?;
208 let d = d.extract::<PyBytes>(py)?;
209 Ok(self.borrow_mut(py)?
209 Ok(self.inner_shared(py).borrow_mut()?
210 .has_tracked_dir(HgPath::new(d.data(py)))
210 .has_tracked_dir(HgPath::new(d.data(py)))
211 .to_py_object(py))
211 .to_py_object(py))
212 }
212 }
213
213
214 def hasdir(&self, d: PyObject) -> PyResult<PyBool> {
214 def hasdir(&self, d: PyObject) -> PyResult<PyBool> {
215 let d = d.extract::<PyBytes>(py)?;
215 let d = d.extract::<PyBytes>(py)?;
216 Ok(self.borrow_mut(py)?
216 Ok(self.inner_shared(py).borrow_mut()?
217 .has_dir(HgPath::new(d.data(py)))
217 .has_dir(HgPath::new(d.data(py)))
218 .to_py_object(py))
218 .to_py_object(py))
219 }
219 }
220
220
221 def parents(&self, st: PyObject) -> PyResult<PyTuple> {
221 def parents(&self, st: PyObject) -> PyResult<PyTuple> {
222 self.borrow_mut(py)?
222 self.inner_shared(py).borrow_mut()?
223 .parents(st.extract::<PyBytes>(py)?.data(py))
223 .parents(st.extract::<PyBytes>(py)?.data(py))
224 .and_then(|d| {
224 .and_then(|d| {
225 Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2))
225 Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2))
@@ -237,13 +237,13 b' py_class!(pub class DirstateMap |py| {'
237 let p1 = extract_node_id(py, &p1)?;
237 let p1 = extract_node_id(py, &p1)?;
238 let p2 = extract_node_id(py, &p2)?;
238 let p2 = extract_node_id(py, &p2)?;
239
239
240 self.borrow_mut(py)?
240 self.inner_shared(py).borrow_mut()?
241 .set_parents(&DirstateParents { p1, p2 });
241 .set_parents(&DirstateParents { p1, p2 });
242 Ok(py.None())
242 Ok(py.None())
243 }
243 }
244
244
245 def read(&self, st: PyObject) -> PyResult<Option<PyObject>> {
245 def read(&self, st: PyObject) -> PyResult<Option<PyObject>> {
246 match self.borrow_mut(py)?
246 match self.inner_shared(py).borrow_mut()?
247 .read(st.extract::<PyBytes>(py)?.data(py))
247 .read(st.extract::<PyBytes>(py)?.data(py))
248 {
248 {
249 Ok(Some(parents)) => Ok(Some(
249 Ok(Some(parents)) => Ok(Some(
@@ -270,7 +270,7 b' py_class!(pub class DirstateMap |py| {'
270 p2: extract_node_id(py, &p2)?,
270 p2: extract_node_id(py, &p2)?,
271 };
271 };
272
272
273 match self.borrow_mut(py)?.pack(parents, now) {
273 match self.inner_shared(py).borrow_mut()?.pack(parents, now) {
274 Ok(packed) => Ok(PyBytes::new(py, &packed)),
274 Ok(packed) => Ok(PyBytes::new(py, &packed)),
275 Err(_) => Err(PyErr::new::<exc::OSError, _>(
275 Err(_) => Err(PyErr::new::<exc::OSError, _>(
276 py,
276 py,
@@ -281,7 +281,9 b' py_class!(pub class DirstateMap |py| {'
281
281
282 def filefoldmapasdict(&self) -> PyResult<PyDict> {
282 def filefoldmapasdict(&self) -> PyResult<PyDict> {
283 let dict = PyDict::new(py);
283 let dict = PyDict::new(py);
284 for (key, value) in self.borrow_mut(py)?.build_file_fold_map().iter() {
284 for (key, value) in
285 self.inner_shared(py).borrow_mut()?.build_file_fold_map().iter()
286 {
285 dict.set_item(py, key.as_ref().to_vec(), value.as_ref().to_vec())?;
287 dict.set_item(py, key.as_ref().to_vec(), value.as_ref().to_vec())?;
286 }
288 }
287 Ok(dict)
289 Ok(dict)
@@ -350,7 +352,7 b' py_class!(pub class DirstateMap |py| {'
350
352
351 def getdirs(&self) -> PyResult<Dirs> {
353 def getdirs(&self) -> PyResult<Dirs> {
352 // TODO don't copy, share the reference
354 // TODO don't copy, share the reference
353 self.borrow_mut(py)?.set_dirs();
355 self.inner_shared(py).borrow_mut()?.set_dirs();
354 Dirs::from_inner(
356 Dirs::from_inner(
355 py,
357 py,
356 DirsMultiset::from_dirstate(
358 DirsMultiset::from_dirstate(
@@ -361,7 +363,7 b' py_class!(pub class DirstateMap |py| {'
361 }
363 }
362 def getalldirs(&self) -> PyResult<Dirs> {
364 def getalldirs(&self) -> PyResult<Dirs> {
363 // TODO don't copy, share the reference
365 // TODO don't copy, share the reference
364 self.borrow_mut(py)?.set_all_dirs();
366 self.inner_shared(py).borrow_mut()?.set_all_dirs();
365 Dirs::from_inner(
367 Dirs::from_inner(
366 py,
368 py,
367 DirsMultiset::from_dirstate(
369 DirsMultiset::from_dirstate(
@@ -434,7 +436,7 b' py_class!(pub class DirstateMap |py| {'
434 ) -> PyResult<PyObject> {
436 ) -> PyResult<PyObject> {
435 let key = key.extract::<PyBytes>(py)?;
437 let key = key.extract::<PyBytes>(py)?;
436 let value = value.extract::<PyBytes>(py)?;
438 let value = value.extract::<PyBytes>(py)?;
437 self.borrow_mut(py)?.copy_map.insert(
439 self.inner_shared(py).borrow_mut()?.copy_map.insert(
438 HgPathBuf::from_bytes(key.data(py)),
440 HgPathBuf::from_bytes(key.data(py)),
439 HgPathBuf::from_bytes(value.data(py)),
441 HgPathBuf::from_bytes(value.data(py)),
440 );
442 );
@@ -447,7 +449,8 b' py_class!(pub class DirstateMap |py| {'
447 ) -> PyResult<Option<PyObject>> {
449 ) -> PyResult<Option<PyObject>> {
448 let key = key.extract::<PyBytes>(py)?;
450 let key = key.extract::<PyBytes>(py)?;
449 match self
451 match self
450 .borrow_mut(py)?
452 .inner_shared(py)
453 .borrow_mut()?
451 .copy_map
454 .copy_map
452 .remove(HgPath::new(key.data(py)))
455 .remove(HgPath::new(key.data(py)))
453 {
456 {
@@ -310,15 +310,6 b' macro_rules! py_shared_ref {'
310 let data = self.$data_member(py);
310 let data = self.$data_member(py);
311 unsafe { PySharedRef::new(py, owner, data) }
311 unsafe { PySharedRef::new(py, owner, data) }
312 }
312 }
313
314 // TODO: remove this function in favor of $shared_accessor(py)
315 fn borrow_mut<'a>(
316 &'a self,
317 py: Python<'a>,
318 ) -> PyResult<crate::ref_sharing::PyRefMut<'a, $inner_struct>>
319 {
320 self.$shared_accessor(py).borrow_mut()
321 }
322 }
313 }
323 };
314 };
324 }
315 }
General Comments 0
You need to be logged in to leave comments. Login now