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
25301fc9
Commit
25301fc9
authored
May 18, 2011
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix finally inside/outside the loop
parent
22cb7155
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
3 deletions
+72
-3
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+9
-3
tests/errors/w_uninitialized_for.pyx
tests/errors/w_uninitialized_for.pyx
+31
-0
tests/errors/w_uninitialized_while.pyx
tests/errors/w_uninitialized_while.pyx
+32
-0
No files found.
Cython/Compiler/FlowControl.py
View file @
25301fc9
...
...
@@ -200,6 +200,7 @@ class LoopDescr(object):
def
__init__
(
self
,
next_block
,
loop_block
):
self
.
next_block
=
next_block
self
.
loop_block
=
loop_block
self
.
exceptions
=
[]
class
ExceptionDescr
(
object
):
"""Exception handling helper.
...
...
@@ -827,12 +828,17 @@ class CreateControlFlowGraph(CythonTransform):
self
.
visit
(
node
.
finally_clause
)
finally_exit
=
self
.
flow
.
block
self
.
flow
.
exceptions
.
append
(
ExceptionDescr
(
entry_point
,
finally_enter
,
finally_exit
))
descr
=
ExceptionDescr
(
entry_point
,
finally_enter
,
finally_exit
)
self
.
flow
.
exceptions
.
append
(
descr
)
if
self
.
flow
.
loops
:
self
.
flow
.
loops
[
-
1
].
exceptions
.
append
(
descr
)
self
.
flow
.
block
=
body_block
## XXX: Is it still required
body_block
.
add_child
(
entry_point
)
self
.
visit
(
node
.
body
)
self
.
flow
.
exceptions
.
pop
()
if
self
.
flow
.
loops
:
self
.
flow
.
loops
[
-
1
].
exceptions
.
pop
()
if
self
.
flow
.
block
:
self
.
flow
.
block
.
add_child
(
finally_enter
)
...
...
@@ -878,7 +884,7 @@ class CreateControlFlowGraph(CythonTransform):
return
node
loop
=
self
.
flow
.
loops
[
-
1
]
self
.
mark_position
(
node
)
for
exception
in
self
.
flow
.
exceptions
[::
-
1
]:
for
exception
in
loop
.
exceptions
[::
-
1
]:
if
exception
.
finally_enter
:
self
.
flow
.
block
.
add_child
(
exception
.
finally_enter
)
if
exception
.
finally_exit
:
...
...
@@ -895,7 +901,7 @@ class CreateControlFlowGraph(CythonTransform):
return
node
loop
=
self
.
flow
.
loops
[
-
1
]
self
.
mark_position
(
node
)
for
exception
in
self
.
flow
.
exceptions
[::
-
1
]:
for
exception
in
loop
.
exceptions
[::
-
1
]:
if
exception
.
finally_enter
:
self
.
flow
.
block
.
add_child
(
exception
.
finally_enter
)
if
exception
.
finally_exit
:
...
...
tests/errors/w_uninitialized_for.pyx
View file @
25301fc9
...
...
@@ -50,6 +50,35 @@ def for_break(l):
x
=
i
print
x
def
for_finally_continue
(
f
):
for
i
in
f
:
try
:
x
=
i
()
finally
:
print
x
continue
def
for_finally_break
(
f
):
for
i
in
f
:
try
:
x
=
i
()
finally
:
print
x
break
def
for_finally_outer
(
p
,
f
):
x
=
1
try
:
for
i
in
f
:
print
x
x
=
i
()
if
x
>
0
:
continue
if
x
<
0
:
break
finally
:
del
x
_ERRORS
=
"""
8:12: local variable 'a' might be referenced before assignment
...
...
@@ -59,4 +88,6 @@ _ERRORS = """
37:16: local variable 'x' might be referenced before assignment
44:11: local variable 'x' might be referenced before assignment
51:11: local variable 'x' might be referenced before assignment
58:19: local variable 'x' might be referenced before assignment
66:19: local variable 'x' might be referenced before assignment
"""
tests/errors/w_uninitialized_while.pyx
View file @
25301fc9
...
...
@@ -24,7 +24,39 @@ def simple_while_pos(n):
a
=
1
return
a
def
while_finally_continue
(
p
,
f
):
while
p
():
try
:
x
=
f
()
finally
:
print
x
continue
def
while_finally_break
(
p
,
f
):
while
p
():
try
:
x
=
f
()
finally
:
print
x
break
def
while_finally_outer
(
p
,
f
):
x
=
1
try
:
while
p
():
print
x
x
=
f
()
if
x
>
0
:
continue
if
x
<
0
:
break
finally
:
del
x
_ERRORS
=
"""
9:12: local variable 'a' might be referenced before assignment
17:12: local variable 'a' might be referenced before assignment
32:19: local variable 'x' might be referenced before assignment
40:19: local variable 'x' might be referenced before assignment
"""
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