Commit d72e4ace authored by da-woods's avatar da-woods Committed by Stefan Behnel

Fixed a bug with C++ comparison operators (GH-3361)

They'd generate two calls - one exception checked and one not
parent 5fe81f40
......@@ -12485,6 +12485,7 @@ class CmpNode(object):
result_code if self.type.is_pyobject else None,
self.exception_value,
self.in_nogil_context)
else:
code.putln(statement)
def c_operator(self, op):
......
......@@ -42,6 +42,10 @@ cdef extern from "cpp_operator_exc_handling_helper.hpp" nogil:
wrapped_int &operator=(const wrapped_int &other) except +ArithmeticError
wrapped_int &operator=(const long long &vao) except +
cdef cppclass second_call_is_different:
second_call_is_different()
bool operator<(const second_call_is_different&) except +
def assert_raised(f, *args, **kwargs):
err = kwargs.get('err', None)
......@@ -268,3 +272,13 @@ def test_operator_exception_handling():
assert_raised(separate_exceptions, 4, 1, 1, 1, 3, err=ArithmeticError)
assert_raised(call_temp_separation, 2, 1, 4, err=AttributeError)
assert_raised(call_temp_separation, 2, 4, 1, err=IndexError)
def test_only_single_call():
"""
Previous version of the operator handling code called the operator twice
(Resulting in a crash)
>>> test_only_single_call()
False
"""
cdef second_call_is_different inst
return inst<inst
......@@ -201,3 +201,16 @@ public:
return *this;
}
};
class second_call_is_different {
int count;
public:
second_call_is_different(): count(0) {}
bool operator<(const second_call_is_different& lhs) {
if (count>0) {
return true;
}
++count;
return false;
}
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment