Commit f6c850d1 authored by Stefan Behnel's avatar Stefan Behnel

Fix a refcounting bug in the new @total_ordering decorator.

See https://github.com/cython/cython/pull/3626
parent ec945fe3
...@@ -2148,11 +2148,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -2148,11 +2148,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# Implement the and/or check with an if. # Implement the and/or check with an if.
if comp_op == '&&': if comp_op == '&&':
code.putln("if (%s order_res) {" % ('!!' if invert_comp else '!')) code.putln("if (%s order_res) {" % ('!!' if invert_comp else '!'))
code.putln("ret = Py_False;") code.putln("ret = __Pyx_NewRef(Py_False);")
code.putln("} else {") code.putln("} else {")
elif comp_op == '||': elif comp_op == '||':
code.putln("if (%s order_res) {" % ('!' if invert_comp else '')) code.putln("if (%s order_res) {" % ('!' if invert_comp else ''))
code.putln("ret = Py_True;") code.putln("ret = __Pyx_NewRef(Py_True);")
code.putln("} else {") code.putln("} else {")
else: else:
raise AssertionError('Unknown op %s' % (comp_op, )) raise AssertionError('Unknown op %s' % (comp_op, ))
......
...@@ -39,6 +39,9 @@ def test_all_comp(cls): ...@@ -39,6 +39,9 @@ def test_all_comp(cls):
expected = func(left.value, right.value) expected = func(left.value, right.value)
try: try:
result = func(left, right) result = func(left, right)
# repeat to rule out deallocation bugs (and assert determinism)
for _ in range(10):
assert result == func(left, right)
except TypeError: except TypeError:
print("TypeError:", left.value, comp, right.value) print("TypeError:", left.value, comp, right.value)
succeeded = False succeeded = 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