##// END OF EJS Templates
rust-cpython: fix unsafe inner(py).borrow_mut() calls...
Yuya Nishihara -
r43114:01d3ce32 default
parent child Browse files
Show More
@@ -169,8 +169,7 b' py_class!(pub class DirstateMap |py| {'
169 Ok(filename?.extract::<PyBytes>(py)?.data(py).to_owned())
169 Ok(filename?.extract::<PyBytes>(py)?.data(py).to_owned())
170 })
170 })
171 .collect();
171 .collect();
172 self.inner(py)
172 self.borrow_mut(py)?
173 .borrow_mut()
174 .clear_ambiguous_times(files?, now.extract(py)?);
173 .clear_ambiguous_times(files?, now.extract(py)?);
175 Ok(py.None())
174 Ok(py.None())
176 }
175 }
@@ -205,25 +204,20 b' py_class!(pub class DirstateMap |py| {'
205
204
206 def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> {
205 def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> {
207 let d = d.extract::<PyBytes>(py)?;
206 let d = d.extract::<PyBytes>(py)?;
208 Ok(self
207 Ok(self.borrow_mut(py)?
209 .inner(py)
210 .borrow_mut()
211 .has_tracked_dir(d.data(py))
208 .has_tracked_dir(d.data(py))
212 .to_py_object(py))
209 .to_py_object(py))
213 }
210 }
214
211
215 def hasdir(&self, d: PyObject) -> PyResult<PyBool> {
212 def hasdir(&self, d: PyObject) -> PyResult<PyBool> {
216 let d = d.extract::<PyBytes>(py)?;
213 let d = d.extract::<PyBytes>(py)?;
217 Ok(self
214 Ok(self.borrow_mut(py)?
218 .inner(py)
219 .borrow_mut()
220 .has_dir(d.data(py))
215 .has_dir(d.data(py))
221 .to_py_object(py))
216 .to_py_object(py))
222 }
217 }
223
218
224 def parents(&self, st: PyObject) -> PyResult<PyTuple> {
219 def parents(&self, st: PyObject) -> PyResult<PyTuple> {
225 self.inner(py)
220 self.borrow_mut(py)?
226 .borrow_mut()
227 .parents(st.extract::<PyBytes>(py)?.data(py))
221 .parents(st.extract::<PyBytes>(py)?.data(py))
228 .and_then(|d| {
222 .and_then(|d| {
229 Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2))
223 Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2))
@@ -241,16 +235,13 b' py_class!(pub class DirstateMap |py| {'
241 let p1 = extract_node_id(py, &p1)?;
235 let p1 = extract_node_id(py, &p1)?;
242 let p2 = extract_node_id(py, &p2)?;
236 let p2 = extract_node_id(py, &p2)?;
243
237
244 self.inner(py)
238 self.borrow_mut(py)?
245 .borrow_mut()
246 .set_parents(&DirstateParents { p1, p2 });
239 .set_parents(&DirstateParents { p1, p2 });
247 Ok(py.None())
240 Ok(py.None())
248 }
241 }
249
242
250 def read(&self, st: PyObject) -> PyResult<Option<PyObject>> {
243 def read(&self, st: PyObject) -> PyResult<Option<PyObject>> {
251 match self
244 match self.borrow_mut(py)?
252 .inner(py)
253 .borrow_mut()
254 .read(st.extract::<PyBytes>(py)?.data(py))
245 .read(st.extract::<PyBytes>(py)?.data(py))
255 {
246 {
256 Ok(Some(parents)) => Ok(Some(
247 Ok(Some(parents)) => Ok(Some(
@@ -353,7 +344,7 b' py_class!(pub class DirstateMap |py| {'
353
344
354 def getdirs(&self) -> PyResult<Dirs> {
345 def getdirs(&self) -> PyResult<Dirs> {
355 // TODO don't copy, share the reference
346 // TODO don't copy, share the reference
356 self.inner(py).borrow_mut().set_dirs();
347 self.borrow_mut(py)?.set_dirs();
357 Dirs::from_inner(
348 Dirs::from_inner(
358 py,
349 py,
359 DirsMultiset::from_dirstate(
350 DirsMultiset::from_dirstate(
@@ -364,7 +355,7 b' py_class!(pub class DirstateMap |py| {'
364 }
355 }
365 def getalldirs(&self) -> PyResult<Dirs> {
356 def getalldirs(&self) -> PyResult<Dirs> {
366 // TODO don't copy, share the reference
357 // TODO don't copy, share the reference
367 self.inner(py).borrow_mut().set_all_dirs();
358 self.borrow_mut(py)?.set_all_dirs();
368 Dirs::from_inner(
359 Dirs::from_inner(
369 py,
360 py,
370 DirsMultiset::from_dirstate(
361 DirsMultiset::from_dirstate(
@@ -422,8 +413,7 b' py_class!(pub class DirstateMap |py| {'
422 ) -> PyResult<PyObject> {
413 ) -> PyResult<PyObject> {
423 let key = key.extract::<PyBytes>(py)?;
414 let key = key.extract::<PyBytes>(py)?;
424 let value = value.extract::<PyBytes>(py)?;
415 let value = value.extract::<PyBytes>(py)?;
425 self.inner(py)
416 self.borrow_mut(py)?
426 .borrow_mut()
427 .copy_map
417 .copy_map
428 .insert(key.data(py).to_vec(), value.data(py).to_vec());
418 .insert(key.data(py).to_vec(), value.data(py).to_vec());
429 Ok(py.None())
419 Ok(py.None())
@@ -434,7 +424,7 b' py_class!(pub class DirstateMap |py| {'
434 default: Option<PyObject>
424 default: Option<PyObject>
435 ) -> PyResult<Option<PyObject>> {
425 ) -> PyResult<Option<PyObject>> {
436 let key = key.extract::<PyBytes>(py)?;
426 let key = key.extract::<PyBytes>(py)?;
437 match self.inner(py).borrow_mut().copy_map.remove(key.data(py)) {
427 match self.borrow_mut(py)?.copy_map.remove(key.data(py)) {
438 Some(_) => Ok(None),
428 Some(_) => Ok(None),
439 None => Ok(default),
429 None => Ok(default),
440 }
430 }
General Comments 0
You need to be logged in to leave comments. Login now