Commit e914ffa1 authored by Xavier Thompson's avatar Xavier Thompson

Fix iteration over temporary cypclass values

parent 2d3f644f
...@@ -2772,7 +2772,14 @@ class IteratorNode(ExprNode): ...@@ -2772,7 +2772,14 @@ class IteratorNode(ExprNode):
def generate_result_code(self, code): def generate_result_code(self, code):
sequence_type = self.sequence.type sequence_type = self.sequence.type
if sequence_type.is_cyp_class: if sequence_type.is_cyp_class:
begin_func = "%s->begin" % self.sequence.result() if self.sequence.is_temp:
self.cpp_iterator_cname = code.funcstate.allocate_temp(sequence_type, manage_ref=False)
code.putln("%s = %s;" % (self.cpp_iterator_cname, self.sequence.result()))
code.put_incref(self.cpp_iterator_cname, sequence_type)
begin_func = "%s->begin" % self.cpp_iterator_cname
else:
begin_func = "%s->begin" % self.sequence.result()
code.putln("%s = %s();" % (self.result(), begin_func)) code.putln("%s = %s();" % (self.result(), begin_func))
return return
elif sequence_type.is_cpp_class: elif sequence_type.is_cpp_class:
...@@ -2883,7 +2890,10 @@ class IteratorNode(ExprNode): ...@@ -2883,7 +2890,10 @@ class IteratorNode(ExprNode):
if self.reversed: if self.reversed:
code.putln("if (%s < 0) break;" % self.counter_cname) code.putln("if (%s < 0) break;" % self.counter_cname)
if sequence_type.is_cyp_class: if sequence_type.is_cyp_class:
end_func = "%s->end" % self.sequence.result() if self.cpp_iterator_cname:
end_func = "%s->end" % self.cpp_iterator_cname
else:
end_func = "%s->end" % self.sequence.result()
code.putln("if (!(%s != %s())) break;" % ( code.putln("if (!(%s != %s())) break;" % (
self.result(), self.result(),
end_func)) end_func))
...@@ -2946,6 +2956,8 @@ class IteratorNode(ExprNode): ...@@ -2946,6 +2956,8 @@ class IteratorNode(ExprNode):
code.funcstate.release_temp(self.iter_func_ptr) code.funcstate.release_temp(self.iter_func_ptr)
self.iter_func_ptr = None self.iter_func_ptr = None
if self.cpp_iterator_cname: if self.cpp_iterator_cname:
if self.sequence.type.is_cyp_class:
code.put_decref(self.cpp_iterator_cname, self.sequence.type)
code.funcstate.release_temp(self.cpp_iterator_cname) code.funcstate.release_temp(self.cpp_iterator_cname)
ExprNode.free_temps(self, code) ExprNode.free_temps(self, code)
......
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