Skip to content

Commit 19dc69c

Browse files
authored
Merge pull request RustPython#3295 from DimitrisJim/cmp_recursions
Handle recursions when comparing objects.
2 parents f44c61e + 54a5db2 commit 19dc69c

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

Lib/test/test_copy.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ def test_deepcopy_list(self):
370370
self.assertIsNot(x, y)
371371
self.assertIsNot(x[0], y[0])
372372

373-
@unittest.skip("TODO: RUSTPYTHON, segmentation fault")
374373
def test_deepcopy_reflexive_list(self):
375374
x = []
376375
x.append(x)
@@ -398,7 +397,6 @@ def test_deepcopy_tuple_of_immutables(self):
398397
y = copy.deepcopy(x)
399398
self.assertIs(x, y)
400399

401-
@unittest.skip("TODO: RUSTPYTHON, segmentation fault")
402400
def test_deepcopy_reflexive_tuple(self):
403401
x = ([],)
404402
x[0].append(x)
@@ -416,7 +414,6 @@ def test_deepcopy_dict(self):
416414
self.assertIsNot(x, y)
417415
self.assertIsNot(x["foo"], y["foo"])
418416

419-
@unittest.skip("TODO: RUSTPYTHON, segmentation fault")
420417
def test_deepcopy_reflexive_dict(self):
421418
x = {}
422419
x['foo'] = x

vm/src/vm.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,8 +1876,6 @@ impl VirtualMachine {
18761876
op: PyComparisonOp,
18771877
) -> PyResult<Either<PyObjectRef, bool>> {
18781878
let swapped = op.swapped();
1879-
// TODO: _Py_EnterRecursiveCall(tstate, " in comparison")
1880-
18811879
let call_cmp = |obj: &PyObjectRef, other, op| {
18821880
let cmp = obj
18831881
.class()
@@ -1896,17 +1894,19 @@ impl VirtualMachine {
18961894
!v_class.is(&w_class) && w_class.issubclass(&v_class)
18971895
};
18981896
if is_strict_subclass {
1899-
let res = call_cmp(w, v, swapped)?;
1897+
let res = self.with_recursion("in comparison", || call_cmp(w, v, swapped))?;
19001898
checked_reverse_op = true;
19011899
if let PyArithmeticValue::Implemented(x) = res {
19021900
return Ok(x);
19031901
}
19041902
}
1905-
if let PyArithmeticValue::Implemented(x) = call_cmp(v, w, op)? {
1903+
if let PyArithmeticValue::Implemented(x) =
1904+
self.with_recursion("in comparison", || call_cmp(v, w, op))?
1905+
{
19061906
return Ok(x);
19071907
}
19081908
if !checked_reverse_op {
1909-
let res = call_cmp(w, v, swapped)?;
1909+
let res = self.with_recursion("in comparison", || call_cmp(w, v, swapped))?;
19101910
if let PyArithmeticValue::Implemented(x) = res {
19111911
return Ok(x);
19121912
}
@@ -1916,7 +1916,6 @@ impl VirtualMachine {
19161916
PyComparisonOp::Ne => Ok(Either::B(!v.is(&w))),
19171917
_ => Err(self.new_unsupported_binop_error(v, w, op.operator_token())),
19181918
}
1919-
// TODO: _Py_LeaveRecursiveCall(tstate);
19201919
}
19211920

19221921
pub fn bool_cmp(&self, a: &PyObjectRef, b: &PyObjectRef, op: PyComparisonOp) -> PyResult<bool> {

0 commit comments

Comments
 (0)