Skip to content

Commit 54a5db2

Browse files
committed
Handle recursions when comparing objects.
1 parent 9c6eaa5 commit 54a5db2

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
@@ -1873,8 +1873,6 @@ impl VirtualMachine {
18731873
op: PyComparisonOp,
18741874
) -> PyResult<Either<PyObjectRef, bool>> {
18751875
let swapped = op.swapped();
1876-
// TODO: _Py_EnterRecursiveCall(tstate, " in comparison")
1877-
18781876
let call_cmp = |obj: &PyObjectRef, other, op| {
18791877
let cmp = obj
18801878
.class()
@@ -1893,17 +1891,19 @@ impl VirtualMachine {
18931891
!v_class.is(&w_class) && w_class.issubclass(&v_class)
18941892
};
18951893
if is_strict_subclass {
1896-
let res = call_cmp(w, v, swapped)?;
1894+
let res = self.with_recursion("in comparison", || call_cmp(w, v, swapped))?;
18971895
checked_reverse_op = true;
18981896
if let PyArithmeticValue::Implemented(x) = res {
18991897
return Ok(x);
19001898
}
19011899
}
1902-
if let PyArithmeticValue::Implemented(x) = call_cmp(v, w, op)? {
1900+
if let PyArithmeticValue::Implemented(x) =
1901+
self.with_recursion("in comparison", || call_cmp(v, w, op))?
1902+
{
19031903
return Ok(x);
19041904
}
19051905
if !checked_reverse_op {
1906-
let res = call_cmp(w, v, swapped)?;
1906+
let res = self.with_recursion("in comparison", || call_cmp(w, v, swapped))?;
19071907
if let PyArithmeticValue::Implemented(x) = res {
19081908
return Ok(x);
19091909
}
@@ -1913,7 +1913,6 @@ impl VirtualMachine {
19131913
PyComparisonOp::Ne => Ok(Either::B(!v.is(&w))),
19141914
_ => Err(self.new_unsupported_binop_error(v, w, op.operator_token())),
19151915
}
1916-
// TODO: _Py_LeaveRecursiveCall(tstate);
19171916
}
19181917

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

0 commit comments

Comments
 (0)