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
Gwenaël Samain
cython
Commits
d0722d34
Commit
d0722d34
authored
Oct 04, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug #372: reassignment to stop bound of for-range loop must not impact loop
parent
f7768620
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
1 deletion
+61
-1
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+12
-1
tests/run/for_in_range_T372.pyx
tests/run/for_in_range_T372.pyx
+49
-0
No files found.
Cython/Compiler/Optimize.py
View file @
d0722d34
...
@@ -224,6 +224,13 @@ class IterationTransform(Visitor.VisitorTransform):
...
@@ -224,6 +224,13 @@ class IterationTransform(Visitor.VisitorTransform):
bound2
=
args
[
1
].
coerce_to_integer
(
self
.
current_scope
)
bound2
=
args
[
1
].
coerce_to_integer
(
self
.
current_scope
)
step
=
step
.
coerce_to_integer
(
self
.
current_scope
)
step
=
step
.
coerce_to_integer
(
self
.
current_scope
)
if
not
isinstance
(
bound2
,
ExprNodes
.
ConstNode
):
# stop bound must be immutable => keep it in a temp var
bound2_is_temp
=
True
bound2
=
UtilNodes
.
LetRefNode
(
bound2
)
else
:
bound2_is_temp
=
False
for_node
=
Nodes
.
ForFromStatNode
(
for_node
=
Nodes
.
ForFromStatNode
(
node
.
pos
,
node
.
pos
,
target
=
node
.
target
,
target
=
node
.
target
,
...
@@ -232,6 +239,10 @@ class IterationTransform(Visitor.VisitorTransform):
...
@@ -232,6 +239,10 @@ class IterationTransform(Visitor.VisitorTransform):
step
=
step
,
body
=
node
.
body
,
step
=
step
,
body
=
node
.
body
,
else_clause
=
node
.
else_clause
,
else_clause
=
node
.
else_clause
,
from_range
=
True
)
from_range
=
True
)
if
bound2_is_temp
:
for_node
=
UtilNodes
.
LetNode
(
bound2
,
for_node
)
return
for_node
return
for_node
def
_transform_dict_iteration
(
self
,
node
,
dict_obj
,
keys
,
values
):
def
_transform_dict_iteration
(
self
,
node
,
dict_obj
,
keys
,
values
):
...
...
tests/run/for_in_range_T372.pyx
0 → 100644
View file @
d0722d34
__doc__
=
u"""
>>> test_modify()
0 1 2 3 4
(4, 0)
>>> test_fix()
0 1 2 3 4
4
>>> test_break()
0 1 2
(2, 0)
>>> test_return()
0 1 2
(2, 0)
"""
def
test_modify
():
cdef
int
i
,
n
=
5
for
i
in
range
(
n
):
print
i
,
n
=
0
print
return
i
,
n
def
test_fix
():
cdef
int
i
for
i
in
range
(
5
):
print
i
,
print
return
i
def
test_break
():
cdef
int
i
,
n
=
5
for
i
in
range
(
n
):
print
i
,
n
=
0
if
i
==
2
:
break
print
return
i
,
n
def
test_return
():
cdef
int
i
,
n
=
5
for
i
in
range
(
n
):
print
i
,
n
=
0
if
i
==
2
:
return
i
,
n
print
return
"FAILED!"
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