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
d3b12483
Commit
d3b12483
authored
Jan 28, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
e22b07eb
9f7256fd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
8 deletions
+64
-8
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+10
-6
tests/memoryview/memoryview.pyx
tests/memoryview/memoryview.pyx
+6
-2
tests/run/uninitialized.py
tests/run/uninitialized.py
+48
-0
No files found.
Cython/Compiler/FlowControl.py
View file @
d3b12483
...
...
@@ -193,9 +193,11 @@ class ControlFlow(object):
def
mark_reference
(
self
,
node
,
entry
):
if
self
.
block
and
self
.
is_tracked
(
entry
):
self
.
block
.
stats
.
append
(
NameReference
(
node
,
entry
))
# Local variable is definitely bound after this reference
if
not
node
.
allow_null
:
self
.
block
.
bounded
.
add
(
entry
)
## XXX: We don't track expression evaluation order so we can't use
## XXX: successful reference as initialization sign.
## # Local variable is definitely bound after this reference
## if not node.allow_null:
## self.block.bounded.add(entry)
self
.
entries
.
add
(
entry
)
def
normalize
(
self
):
...
...
@@ -548,9 +550,9 @@ def check_definitions(flow, compiler_directives):
references
[
stat
.
node
]
=
stat
.
entry
stat
.
entry
.
cf_references
.
append
(
stat
)
stat
.
node
.
cf_state
.
update
(
state
)
if
not
stat
.
node
.
allow_null
:
i_state
&=
~
i_assmts
.
bit
# after successful read, the state is known to be initialised
##
if not stat.node.allow_null:
##
i_state &= ~i_assmts.bit
#
# #
after successful read, the state is known to be initialised
state
.
discard
(
Uninitialized
)
state
.
discard
(
Unknown
)
for
assmt
in
state
:
...
...
@@ -1121,6 +1123,7 @@ class ControlFlowAnalysis(CythonTransform):
## XXX: links to exception handling point should be added by
## XXX: children nodes
self
.
flow
.
block
.
add_child
(
entry_point
)
self
.
flow
.
nextblock
()
self
.
_visit
(
node
.
body
)
self
.
flow
.
exceptions
.
pop
()
...
...
@@ -1181,6 +1184,7 @@ class ControlFlowAnalysis(CythonTransform):
self
.
flow
.
block
=
body_block
## XXX: Is it still required
body_block
.
add_child
(
entry_point
)
self
.
flow
.
nextblock
()
self
.
_visit
(
node
.
body
)
self
.
flow
.
exceptions
.
pop
()
if
self
.
flow
.
loops
:
...
...
tests/memoryview/memoryview.pyx
View file @
d3b12483
...
...
@@ -175,6 +175,7 @@ def test_cdef_attribute():
>>> test_cdef_attribute()
Memoryview is not initialized
local variable 'myview' referenced before assignment
local variable 'myview' referenced before assignment
get_ext_obj called
Memoryview is not initialized
<MemoryView of 'array' object>
...
...
@@ -195,8 +196,11 @@ def test_cdef_attribute():
else
:
print
"No UnboundLocalError was raised"
# uninitialized assignment is valid
cdef
int
[:]
otherview
=
myview
cdef
int
[:]
otherview
try
:
otherview
=
myview
except
UnboundLocalError
,
e
:
print
e
.
args
[
0
]
try
:
print
get_ext_obj
().
mview
...
...
tests/run/uninitialized.py
View file @
d3b12483
...
...
@@ -129,3 +129,51 @@ def test_class(cond):
class
A
:
x
=
1
return
A
.
x
def
test_try_except_regression
(
c
):
"""
>>> test_try_except_regression(True)
(123,)
>>> test_try_except_regression(False)
Traceback (most recent call last):
...
UnboundLocalError: local variable 'a' referenced before assignment
"""
if
c
:
a
=
(
123
,)
try
:
return
a
except
:
return
a
def
test_try_finally_regression
(
c
):
"""
>>> test_try_finally_regression(True)
(123,)
>>> test_try_finally_regression(False)
Traceback (most recent call last):
...
UnboundLocalError: local variable 'a' referenced before assignment
"""
if
c
:
a
=
(
123
,)
try
:
return
a
finally
:
return
a
def
test_expression_calculation_order_bug
(
a
):
"""
>>> test_expression_calculation_order_bug(False)
[]
>>> test_expression_calculation_order_bug(True)
Traceback (most recent call last):
...
UnboundLocalError: local variable 'b' referenced before assignment
"""
if
not
a
:
b
=
[]
return
(
a
or
b
)
and
(
b
or
a
)
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