Commit a66ffc46 authored by Xavier Thompson's avatar Xavier Thompson

Refactor handling of new references

parent 8cfda3ec
...@@ -737,6 +737,11 @@ class ExprNode(Node): ...@@ -737,6 +737,11 @@ class ExprNode(Node):
# a subnode. # a subnode.
return self.is_temp return self.is_temp
def result_is_new_reference(self):
# Return true if the result is a new reference that is
# already incref-ed and will need to be decref-ed later.
return self.result_in_temp()
def target_code(self): def target_code(self):
# Return code fragment for use as LHS of a C assignment. # Return code fragment for use as LHS of a C assignment.
return self.calculate_result_code() return self.calculate_result_code()
...@@ -786,7 +791,7 @@ class ExprNode(Node): ...@@ -786,7 +791,7 @@ class ExprNode(Node):
Make sure we own a reference to result. Make sure we own a reference to result.
If the result is in a temp, it is already a new reference. If the result is in a temp, it is already a new reference.
""" """
if not self.result_in_temp(): if not self.result_is_new_reference():
# FIXME: is this verification really necessary ? # FIXME: is this verification really necessary ?
if self.type.is_cyp_class and "NULL" in self.result(): if self.type.is_cyp_class and "NULL" in self.result():
pass pass
...@@ -798,7 +803,7 @@ class ExprNode(Node): ...@@ -798,7 +803,7 @@ class ExprNode(Node):
Make sure we own the reference to this memoryview slice. Make sure we own the reference to this memoryview slice.
""" """
# TODO ideally this would be shared with "make_owned_reference" # TODO ideally this would be shared with "make_owned_reference"
if not self.result_in_temp(): if not self.result_is_new_reference():
code.put_incref_memoryviewslice(self.result(), self.type, code.put_incref_memoryviewslice(self.result(), self.type,
have_gil=not self.in_nogil_context) have_gil=not self.in_nogil_context)
...@@ -4247,13 +4252,13 @@ class IndexNode(_IndexingBaseNode): ...@@ -4247,13 +4252,13 @@ class IndexNode(_IndexingBaseNode):
temp.use_managed_ref = False temp.use_managed_ref = False
return temp return temp
def make_owned_reference(self, code): def result_is_new_reference(self):
if self.type.is_cyp_class and not (self.base.type.is_array or self.base.type.is_ptr): if self.type.is_cyp_class and not (self.base.type.is_array or self.base.type.is_ptr):
# This is already a new reference # This is already a new reference
# either via cpp operator[] # either via cpp operator[]
# or via cypclass __getitem__ # or via cypclass __getitem__
return return True
ExprNode.make_owned_reference(self, code) return ExprNode.result_is_new_reference(self)
gil_message = "Indexing Python object" gil_message = "Indexing Python object"
...@@ -8035,7 +8040,7 @@ class SequenceNode(ExprNode): ...@@ -8035,7 +8040,7 @@ class SequenceNode(ExprNode):
for i in range(arg_count): for i in range(arg_count):
arg = self.args[i] arg = self.args[i]
if c_mult or not arg.result_in_temp(): if c_mult or not arg.result_is_new_reference():
code.put_incref(arg.result(), arg.ctype()) code.put_incref(arg.result(), arg.ctype())
arg.generate_giveref(code) arg.generate_giveref(code)
code.putln("%s(%s, %s, %s);" % ( code.putln("%s(%s, %s, %s);" % (
......
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