From ae62e5eefbecba7f3476cbe092d3b8da35a86c81 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Tue, 24 Jul 2012 19:30:32 +0200 Subject: [PATCH] enable previously unused optimisation code for bytes iteration (found via coverage analysis) --- Cython/Compiler/Optimize.py | 2 +- tests/run/carray_slicing.pyx | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index 978f556..57a93a8 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -237,7 +237,7 @@ class IterationTransform(Visitor.VisitorTransform): def _transform_bytes_iteration(self, node, slice_node, reversed=False): target_type = node.target.type - if not target_type.is_int: + if not target_type.is_int and target_type is not Builtin.bytes_type: # bytes iteration returns bytes objects in Py2, but # integers in Py3 return node diff --git a/tests/run/carray_slicing.pyx b/tests/run/carray_slicing.pyx index b834e2d..dbfdb74 100644 --- a/tests/run/carray_slicing.pyx +++ b/tests/run/carray_slicing.pyx @@ -46,6 +46,21 @@ def slice_charptr_for_loop_c(): print [ chr(c) for c in cstring[1:5] ] print [ chr(c) for c in cstring[4:9] ] +#@cython.test_assert_path_exists("//ForFromStatNode", +# "//ForFromStatNode//IndexNode") +#@cython.test_fail_if_path_exists("//ForInStatNode") +def slice_charptr_for_loop_c_to_bytes(): + """ + >>> slice_charptr_for_loop_c_to_bytes() + ['a', 'b', 'c'] + ['b', 'c', 'A', 'B'] + ['B', 'C', 'q', 't', 'p'] + """ + cdef bytes b + print [ b for b in cstring[:3] ] + print [ b for b in cstring[1:5] ] + print [ b for b in cstring[4:9] ] + @cython.test_assert_path_exists("//ForFromStatNode", "//ForFromStatNode//IndexNode") @cython.test_fail_if_path_exists("//ForInStatNode") -- 2.7.4