Commit 940fed5e authored by Stefan Behnel's avatar Stefan Behnel

fix ticket #533: 'continue' in the 'else' block of a for-in-loop leaks a reference

parent efabce0a
......@@ -4095,10 +4095,27 @@ class ForInStatNode(LoopNode, StatNode):
"}")
break_label = code.break_label
code.set_loop_labels(old_loop_labels)
if self.else_clause:
# in nested loops, the 'else' block can contain a
# 'continue' statement for the outer loop, but we may need
# to generate cleanup code before taking that path, so we
# intercept it here
orig_continue_label = code.continue_label
code.continue_label = code.new_label('outer_continue')
code.putln("/*else*/ {")
self.else_clause.generate_execution_code(code)
code.putln("}")
if code.label_used(code.continue_label):
code.put_goto(break_label)
code.put_label(code.continue_label)
self.iterator.generate_disposal_code(code)
code.put_goto(orig_continue_label)
code.set_loop_labels(old_loop_labels)
if code.label_used(break_label):
code.put_label(break_label)
self.iterator.release_counter_temp(code)
self.iterator.generate_disposal_code(code)
......
......@@ -2,6 +2,9 @@
def for_in():
"""
>>> for_in()
CONTINUE -1
CONTINUE 4
BREAK 6
6
"""
i = -1
......@@ -10,6 +13,28 @@ def for_in():
if i > 5:
break
else:
print "CONTINUE", i
continue
print "BREAK", i
break
return i
def for_from():
"""
>>> for_from()
CONTINUE 0
CONTINUE 5
BREAK 6
6
"""
i = -1
for L in [[], range(5), range(10)]:
for i from 0 <= i < len(L):
if i > 5:
break
else:
print "CONTINUE", i
continue
print "BREAK", i
break
return i
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