Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
940fed5e
Commit
940fed5e
authored
May 09, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ticket #533: 'continue' in the 'else' block of a for-in-loop leaks a reference
parent
efabce0a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletion
+43
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+18
-1
tests/run/for_in_break_continue_T533.pyx
tests/run/for_in_break_continue_T533.pyx
+25
-0
No files found.
Cython/Compiler/Nodes.py
View file @
940fed5e
...
@@ -4095,11 +4095,28 @@ class ForInStatNode(LoopNode, StatNode):
...
@@ -4095,11 +4095,28 @@ class ForInStatNode(LoopNode, StatNode):
"}"
)
"}"
)
break_label
=
code
.
break_label
break_label
=
code
.
break_label
code
.
set_loop_labels
(
old_loop_labels
)
code
.
set_loop_labels
(
old_loop_labels
)
if
self
.
else_clause
:
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*/ {"
)
code
.
putln
(
"/*else*/ {"
)
self
.
else_clause
.
generate_execution_code
(
code
)
self
.
else_clause
.
generate_execution_code
(
code
)
code
.
putln
(
"}"
)
code
.
putln
(
"}"
)
code
.
put_label
(
break_label
)
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
.
release_counter_temp
(
code
)
self
.
iterator
.
generate_disposal_code
(
code
)
self
.
iterator
.
generate_disposal_code
(
code
)
self
.
iterator
.
free_temps
(
code
)
self
.
iterator
.
free_temps
(
code
)
...
...
tests/run/for_in_break_continue_T533.pyx
View file @
940fed5e
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
def
for_in
():
def
for_in
():
"""
"""
>>> for_in()
>>> for_in()
CONTINUE -1
CONTINUE 4
BREAK 6
6
6
"""
"""
i
=
-
1
i
=
-
1
...
@@ -10,6 +13,28 @@ def for_in():
...
@@ -10,6 +13,28 @@ def for_in():
if
i
>
5
:
if
i
>
5
:
break
break
else
:
else
:
print
"CONTINUE"
,
i
continue
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
break
return
i
return
i
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment