Commit 569b939d authored by Xavier Thompson's avatar Xavier Thompson

Fix 'recover' reference counting

parent 8651295c
......@@ -11451,6 +11451,10 @@ class RecoverNode(ExprNode):
code.putln("#ifdef WITH_THREAD")
code.putln("PyGILState_Release(_save);")
code.putln("#endif")
if self.is_temp:
code.putln("%s = NULL;" % result_code)
if self.solid_operand.result_is_new_reference():
self.operand.generate_disposal_code(code)
code.putln(
code.error_goto(self.pos))
code.putln("}")
......
......@@ -61,6 +61,55 @@ def test_recover_and_drop_name():
return 0
cdef cypclass DoubleRefcounted(Refcounted):
DoubleRefcounted get_self(self):
return self
def test_recover_and_drop_aliased_temporary():
"""
>>> test_recover_and_drop_aliased_temporary()
'recover' operand is not isolated
Refcounted destroyed
0
"""
r = DoubleRefcounted()
if Cy_GETREF(r) != 2:
return -1
try:
recover r.get_self()
return -2
except TypeError as e:
print(e)
if Cy_GETREF(r) != 2:
return -3
return 0
def test_recover_and_drop_cast_aliased_temporary():
"""
>>> test_recover_and_drop_cast_aliased_temporary()
'recover' operand is not isolated
Refcounted destroyed
0
"""
r = DoubleRefcounted()
if Cy_GETREF(r) != 2:
return -1
try:
recover <DoubleRefcounted> r.get_self()
return -2
except TypeError as e:
print(e)
if Cy_GETREF(r) != 2:
return -3
return 0
def test_recover_constructed():
"""
>>> test_recover_constructed()
......
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