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):
def generate_result_code(self, code):
sequence_type = self.sequence.type
if sequence_type.is_cyp_class:
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))
return
elif sequence_type.is_cpp_class:
......@@ -2883,6 +2890,9 @@ class IteratorNode(ExprNode):
if self.reversed:
code.putln("if (%s < 0) break;" % self.counter_cname)
if sequence_type.is_cyp_class:
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;" % (
self.result(),
......@@ -2946,6 +2956,8 @@ class IteratorNode(ExprNode):
code.funcstate.release_temp(self.iter_func_ptr)
self.iter_func_ptr = None
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)
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