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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
e2ac5fa7
Commit
e2ac5fa7
authored
Sep 27, 2011
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix infinite recursion in CF based None-check removal
parent
7deca631
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
2 deletions
+43
-2
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+12
-2
tests/run/cf_none.pyx
tests/run/cf_none.pyx
+31
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
e2ac5fa7
...
@@ -1483,12 +1483,22 @@ class NameNode(AtomicExprNode):
...
@@ -1483,12 +1483,22 @@ class NameNode(AtomicExprNode):
def
may_be_none
(
self
):
def
may_be_none
(
self
):
if
self
.
cf_state
:
if
self
.
cf_state
:
# gard against infinite recursion on self-dependencies
if
getattr
(
self
,
'_none_checking'
,
False
):
# self-dependency - either this node receives a None
# value from *another* node, or it can not reference
# None at this point => safe to assume "not None"
return
False
self
.
_none_checking
=
True
# evaluate control flow state to see if there were any
# evaluate control flow state to see if there were any
# potential None values assigned to the node so far
# potential None values assigned to the node so far
may_be_none
=
False
for
assignment
in
self
.
cf_state
:
for
assignment
in
self
.
cf_state
:
if
assignment
.
rhs
.
may_be_none
():
if
assignment
.
rhs
.
may_be_none
():
return
True
may_be_none
=
True
return
False
break
del
self
.
_none_checking
return
may_be_none
return
super
(
NameNode
,
self
).
may_be_none
()
return
super
(
NameNode
,
self
).
may_be_none
()
def
nonlocally_immutable
(
self
):
def
nonlocally_immutable
(
self
):
...
...
tests/run/cf_none.pyx
View file @
e2ac5fa7
...
@@ -82,3 +82,34 @@ def conditional_not_none(a, dict d not None):
...
@@ -82,3 +82,34 @@ def conditional_not_none(a, dict d not None):
if
a
:
if
a
:
d
=
{}
d
=
{}
return
d
.
get
(
1
)
return
d
.
get
(
1
)
@
cython
.
test_fail_if_path_exists
(
'//NoneCheckNode'
)
def
self_dependency
(
int
x
):
"""
>>> self_dependency(1)
(1, 2)
>>> self_dependency(2)
(None, None)
"""
cdef
dict
a
,
b
a
=
{
1
:
2
}
b
=
{
2
:
1
}
for
i
in
range
(
x
):
a
,
b
=
b
,
a
return
a
.
get
(
2
),
b
.
get
(
1
)
@
cython
.
test_assert_path_exists
(
'//NoneCheckNode'
)
def
self_dependency_none
(
int
x
):
"""
>>> self_dependency_none(False)
1
>>> self_dependency_none(True)
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'get'
"""
cdef
dict
a
,
b
a
=
None
b
=
{
2
:
1
}
if
x
:
a
,
b
=
b
,
a
return
b
.
get
(
2
)
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