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
f27a5ba2
Commit
f27a5ba2
authored
May 13, 2011
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
properly fix (sliced) iteration over bytes objects
parent
4a8ce7c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
14 deletions
+4
-14
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+2
-11
tests/run/for_in_string.pyx
tests/run/for_in_string.pyx
+2
-3
No files found.
Cython/Compiler/Optimize.py
View file @
f27a5ba2
...
...
@@ -153,12 +153,6 @@ class IterationTransform(Visitor.VisitorTransform):
node
,
dict_obj
=
iterator
,
keys
=
True
,
values
=
False
)
# C array (slice) iteration?
if
False
:
plain_iterator
=
unwrap_coerced_node
(
iterator
)
if
isinstance
(
plain_iterator
,
ExprNodes
.
SliceIndexNode
)
and
\
(
plain_iterator
.
base
.
type
.
is_array
or
plain_iterator
.
base
.
type
.
is_ptr
):
return
self
.
_transform_carray_iteration
(
node
,
plain_iterator
,
reversed
=
reversed
)
if
iterator
.
type
.
is_ptr
or
iterator
.
type
.
is_array
:
return
self
.
_transform_carray_iteration
(
node
,
iterator
,
reversed
=
reversed
)
if
iterator
.
type
in
(
Builtin
.
bytes_type
,
Builtin
.
unicode_type
):
...
...
@@ -248,8 +242,6 @@ class IterationTransform(Visitor.VisitorTransform):
])
def
_transform_string_iteration
(
self
,
node
,
slice_node
,
reversed
=
False
):
if
not
node
.
target
.
type
.
is_int
:
return
self
.
_transform_carray_iteration
(
node
,
slice_node
)
if
slice_node
.
type
is
Builtin
.
unicode_type
:
unpack_func
=
"PyUnicode_AS_UNICODE"
len_func
=
"PyUnicode_GET_SIZE"
...
...
@@ -303,6 +295,7 @@ class IterationTransform(Visitor.VisitorTransform):
if
not
slice_base
.
type
.
is_pyobject
:
error
(
slice_node
.
pos
,
"C array iteration requires known end index"
)
return
node
elif
isinstance
(
slice_node
,
ExprNodes
.
IndexNode
):
assert
isinstance
(
slice_node
.
index
,
ExprNodes
.
SliceNode
)
slice_base
=
slice_node
.
base
...
...
@@ -329,6 +322,7 @@ class IterationTransform(Visitor.VisitorTransform):
step
=
ExprNodes
.
IntNode
(
step
.
pos
,
type
=
PyrexTypes
.
c_py_ssize_t_type
,
value
=
str
(
abs
(
step_value
)),
constant_result
=
abs
(
step_value
))
elif
slice_node
.
type
.
is_array
:
if
slice_node
.
type
.
size
is
None
:
error
(
step
.
pos
,
"C array iteration requires known end index"
)
...
...
@@ -415,9 +409,6 @@ class IterationTransform(Visitor.VisitorTransform):
elif
node
.
target
.
type
.
is_ptr
and
not
node
.
target
.
type
.
assignable_from
(
ptr_type
.
base_type
):
# Allow iteration with pointer target to avoid copy.
target_value
=
counter_temp
elif
ptr_type
is
Builtin
.
bytes_type
:
# TODO: implement ...
return
node
else
:
target_value
=
ExprNodes
.
IndexNode
(
node
.
target
.
pos
,
...
...
tests/run/for_in_string.pyx
View file @
f27a5ba2
...
...
@@ -49,9 +49,8 @@ def for_char_in_bytes(bytes s):
else
:
return
'X'
# TODO: implement (see Optimize.py:IterationTransform._transform_carray_iteration())
#@cython.test_assert_path_exists("//ForFromStatNode")
#@cython.test_fail_if_path_exists("//ForInStatNode")
@
cython
.
test_assert_path_exists
(
"//ForFromStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//ForInStatNode"
)
def
for_obj_in_bytes_slice
(
bytes
s
):
"""
>>> for_obj_in_bytes_slice(bytes_abc)
...
...
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