Merge pull request #3295 from DimitrisJim/cmp_recursions

Handle recursions when comparing objects.
This commit is contained in:
Jeong YunWon
2021-10-14 16:54:58 +09:00
committed by GitHub
2 changed files with 5 additions and 9 deletions

View File

@@ -370,7 +370,6 @@ class TestCopy(unittest.TestCase):
self.assertIsNot(x, y)
self.assertIsNot(x[0], y[0])
@unittest.skip("TODO: RUSTPYTHON, segmentation fault")
def test_deepcopy_reflexive_list(self):
x = []
x.append(x)
@@ -398,7 +397,6 @@ class TestCopy(unittest.TestCase):
y = copy.deepcopy(x)
self.assertIs(x, y)
@unittest.skip("TODO: RUSTPYTHON, segmentation fault")
def test_deepcopy_reflexive_tuple(self):
x = ([],)
x[0].append(x)
@@ -416,7 +414,6 @@ class TestCopy(unittest.TestCase):
self.assertIsNot(x, y)
self.assertIsNot(x["foo"], y["foo"])
@unittest.skip("TODO: RUSTPYTHON, segmentation fault")
def test_deepcopy_reflexive_dict(self):
x = {}
x['foo'] = x

View File

@@ -1876,8 +1876,6 @@ impl VirtualMachine {
op: PyComparisonOp,
) -> PyResult<Either<PyObjectRef, bool>> {
let swapped = op.swapped();
// TODO: _Py_EnterRecursiveCall(tstate, " in comparison")
let call_cmp = |obj: &PyObjectRef, other, op| {
let cmp = obj
.class()
@@ -1896,17 +1894,19 @@ impl VirtualMachine {
!v_class.is(&w_class) && w_class.issubclass(&v_class)
};
if is_strict_subclass {
let res = call_cmp(w, v, swapped)?;
let res = self.with_recursion("in comparison", || call_cmp(w, v, swapped))?;
checked_reverse_op = true;
if let PyArithmeticValue::Implemented(x) = res {
return Ok(x);
}
}
if let PyArithmeticValue::Implemented(x) = call_cmp(v, w, op)? {
if let PyArithmeticValue::Implemented(x) =
self.with_recursion("in comparison", || call_cmp(v, w, op))?
{
return Ok(x);
}
if !checked_reverse_op {
let res = call_cmp(w, v, swapped)?;
let res = self.with_recursion("in comparison", || call_cmp(w, v, swapped))?;
if let PyArithmeticValue::Implemented(x) = res {
return Ok(x);
}
@@ -1916,7 +1916,6 @@ impl VirtualMachine {
PyComparisonOp::Ne => Ok(Either::B(!v.is(&w))),
_ => Err(self.new_unsupported_binop_error(v, w, op.operator_token())),
}
// TODO: _Py_LeaveRecursiveCall(tstate);
}
pub fn bool_cmp(&self, a: &PyObjectRef, b: &PyObjectRef, op: PyComparisonOp) -> PyResult<bool> {