forked from Rust-related/RustPython
Merge pull request #3295 from DimitrisJim/cmp_recursions
Handle recursions when comparing objects.
This commit is contained in:
3
Lib/test/test_copy.py
vendored
3
Lib/test/test_copy.py
vendored
@@ -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
|
||||
|
||||
11
vm/src/vm.rs
11
vm/src/vm.rs
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user