From: Stefan Behnel Date: Fri, 3 Sep 2010 19:57:10 +0000 (+0200) Subject: fix char* string iteration when we actually need to coerce to a Python string for... X-Git-Tag: 0.14.alpha0~352 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f1d781a6a0c26ba135893be5ca2bb551bf6d5eeb;p=cython.git fix char* string iteration when we actually need to coerce to a Python string for iteration --- 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):