Commit 4a8ce7c1 authored by Stefan Behnel's avatar Stefan Behnel

fix compiler crash on sliced bytes iteration by disabling the optimisation, minor cleanups

parent 9b67cc67
......@@ -157,7 +157,7 @@ class IterationTransform(Visitor.VisitorTransform):
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)
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)
......@@ -304,7 +304,7 @@ class IterationTransform(Visitor.VisitorTransform):
error(slice_node.pos, "C array iteration requires known end index")
return node
elif isinstance(slice_node, ExprNodes.IndexNode):
# slice_node.index must be a SliceNode
assert isinstance(slice_node.index, ExprNodes.SliceNode)
slice_base = slice_node.base
index = slice_node.index
start = index.start
......@@ -415,6 +415,9 @@ 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,
......
......@@ -49,6 +49,26 @@ 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")
def for_obj_in_bytes_slice(bytes s):
"""
>>> for_obj_in_bytes_slice(bytes_abc)
'X'
>>> for_obj_in_bytes_slice(bytes_ABC)
'B'
>>> for_obj_in_bytes_slice(bytes_abc_null)
'X'
>>> for_obj_in_bytes_slice(bytes_ABC_null)
'B'
"""
for c in s[1:-1]:
if c == b'B':
return 'B'
else:
return 'X'
@cython.test_assert_path_exists("//ForFromStatNode")
@cython.test_fail_if_path_exists("//ForInStatNode")
def for_char_in_enumerate_bytes(bytes s):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment