From f1d781a6a0c26ba135893be5ca2bb551bf6d5eeb Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 3 Sep 2010 21:57:10 +0200 Subject: [PATCH] fix char* string iteration when we actually need to coerce to a Python string for iteration --- Cython/Compiler/Optimize.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index 316fcd41..3f03d571 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -90,15 +90,16 @@ class IterationTransform(Visitor.VisitorTransform): node, dict_obj=iterator, keys=True, values=False) # C array (slice) iteration? + plain_iterator = iterator if isinstance(iterator, ExprNodes.CoerceToPyTypeNode): - iterator = iterator.arg - if isinstance(iterator, ExprNodes.SliceIndexNode) and \ - (iterator.base.type.is_array or iterator.base.type.is_ptr): - return self._transform_carray_iteration(node, iterator) - elif isinstance(iterator, ExprNodes.IndexNode) and \ - isinstance(iterator.index, (ExprNodes.SliceNode, ExprNodes.CoerceFromPyTypeNode)) and \ - (iterator.base.type.is_array or iterator.base.type.is_ptr): - return self._transform_carray_iteration(node, iterator) + plain_iterator = iterator.arg + 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) + elif isinstance(plain_iterator, ExprNodes.IndexNode) and \ + isinstance(plain_iterator.index, (ExprNodes.SliceNode, ExprNodes.CoerceFromPyTypeNode)) and \ + (plain_iterator.base.type.is_array or plain_iterator.base.type.is_ptr): + return self._transform_carray_iteration(node, plain_iterator) elif iterator.type.is_array: return self._transform_carray_iteration(node, iterator) elif iterator.type in (Builtin.bytes_type, Builtin.unicode_type): -- 2.26.2