Commit 3c2d60a1 authored by Xavier Thompson's avatar Xavier Thompson

Fix reference counting in 'consume' operations

parent 5ea4b23c
......@@ -11410,10 +11410,9 @@ class ConsumeNode(ExprNode):
self.generate_runtime_check = True
self.type = PyrexTypes.cyp_class_qualified_type(operand_type, 'iso~')
self.operand_is_named = self.operand.is_name or self.operand.is_attribute
self.is_temp = self.operand_is_named or self.generate_runtime_check
if self.is_temp:
# We steal the reference of the operand.
self.use_managed_ref = False
self.is_temp = self.operand_is_named or (self.generate_runtime_check and not self.operand.is_temp)
if not self.operand_is_named and not self.generate_runtime_check:
return self.operand
return self
def may_be_none(self):
......@@ -11429,11 +11428,13 @@ class ConsumeNode(ExprNode):
def calculate_result_code(self):
return self.operand.result()
def result_in_temp(self):
return self.is_temp or self.operand.result_in_temp()
def generate_result_code(self, code):
if self.is_temp:
operand_result = self.operand.result()
result_code = self.result()
code.putln("%s = %s;" % (result_code, operand_result))
if self.is_temp:
code.putln("%s = %s;" % (result_code, self.operand.result()))
if self.generate_runtime_check:
code.putln("if (%s != NULL && !%s->CyObject_iso()) {" % (result_code, result_code))
if self.nogil:
......@@ -11448,11 +11449,11 @@ class ConsumeNode(ExprNode):
code.putln(
code.error_goto(self.pos))
code.putln("}")
# We steal the reference of the operand.
code.putln("%s = NULL;" % operand_result)
if self.operand.is_temp:
# TODO: steal the reference of the operand instead
code.put_incref(self.result(), self.type)
if self.operand_is_named:
code.putln("%s = NULL;" % self.operand.result())
def generate_post_assignment_code(self, code):
self.operand.generate_post_assignment_code(code)
class TypeidNode(ExprNode):
......
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