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
e4742fe3
Commit
e4742fe3
authored
Jun 15, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug #544: handle side-effects in flattened in-list tests correctly
parent
0d04f2bb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
1 deletion
+34
-1
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+9
-1
tests/run/in_list_with_side_effects_T544.pyx
tests/run/in_list_with_side_effects_T544.pyx
+25
-0
No files found.
Cython/Compiler/Optimize.py
View file @
e4742fe3
...
@@ -803,7 +803,12 @@ class FlattenInListTransform(Visitor.VisitorTransform, SkipDeclarations):
...
@@ -803,7 +803,12 @@ class FlattenInListTransform(Visitor.VisitorTransform, SkipDeclarations):
lhs
=
UtilNodes
.
ResultRefNode
(
node
.
operand1
)
lhs
=
UtilNodes
.
ResultRefNode
(
node
.
operand1
)
conds
=
[]
conds
=
[]
temps
=
[]
for
arg
in
args
:
for
arg
in
args
:
if
not
arg
.
is_simple
():
# must evaluate all non-simple RHS before doing the comparisons
arg
=
UtilNodes
.
LetRefNode
(
arg
)
temps
.
append
(
arg
)
cond
=
ExprNodes
.
PrimaryCmpNode
(
cond
=
ExprNodes
.
PrimaryCmpNode
(
pos
=
node
.
pos
,
pos
=
node
.
pos
,
operand1
=
lhs
,
operand1
=
lhs
,
...
@@ -822,7 +827,10 @@ class FlattenInListTransform(Visitor.VisitorTransform, SkipDeclarations):
...
@@ -822,7 +827,10 @@ class FlattenInListTransform(Visitor.VisitorTransform, SkipDeclarations):
operand2
=
right
)
operand2
=
right
)
condition
=
reduce
(
concat
,
conds
)
condition
=
reduce
(
concat
,
conds
)
return
UtilNodes
.
EvalWithTempExprNode
(
lhs
,
condition
)
new_node
=
UtilNodes
.
EvalWithTempExprNode
(
lhs
,
condition
)
for
temp
in
temps
[::
-
1
]:
new_node
=
UtilNodes
.
EvalWithTempExprNode
(
temp
,
new_node
)
return
new_node
visit_Node
=
Visitor
.
VisitorTransform
.
recurse_to_children
visit_Node
=
Visitor
.
VisitorTransform
.
recurse_to_children
...
...
tests/run/in_list_with_side_effects_T544.pyx
0 → 100644
View file @
e4742fe3
def
count
(
i
=
[
0
]):
i
[
0
]
+=
1
return
i
[
0
]
def
test
(
x
):
"""
>>> def py_count(i=[0]):
... i[0] += 1
... return i[0]
>>> 1 in (py_count(), py_count(), py_count(), py_count())
True
>>> 4 in (py_count(), py_count(), py_count(), py_count())
False
>>> 12 in (py_count(), py_count(), py_count(), py_count())
True
>>> test(1)
True
>>> test(4)
False
>>> test(12)
True
"""
return
x
in
(
count
(),
count
(),
count
(),
count
())
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