From: Stefan Behnel Date: Thu, 29 Oct 2009 11:59:58 +0000 (+0100) Subject: fix #442: non-pyobject for-in-loop targets failed with enumerate() optimisation X-Git-Tag: 0.12.alpha0~8^2~15 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d19d639632013cb02c02cd2e6431af151a645c28;p=cython.git fix #442: non-pyobject for-in-loop targets failed with enumerate() optimisation --- diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index e1154f30..a7dda28d 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -236,10 +236,6 @@ class IterationTransform(Visitor.VisitorTransform): if not counter_type.is_pyobject and not counter_type.is_int: # nothing we can do here, I guess return node - - if iterable_target.type is not PyrexTypes.py_object_type: - # this may need conversion, could be made to work - return node temp = UtilNodes.LetRefNode(ExprNodes.IntNode(enumerate_function.pos, value='0', @@ -276,6 +272,7 @@ class IterationTransform(Visitor.VisitorTransform): stats = loop_body) node.target = iterable_target + node.item = node.item.coerce_to(iterable_target.type, self.current_scope) node.iterator.sequence = enumerate_function.arg_tuple.args[0] # recurse into loop to check for further optimisations diff --git a/tests/run/enumerate_T316.pyx b/tests/run/enumerate_T316.pyx index d48a4942..5b66c6bb 100644 --- a/tests/run/enumerate_T316.pyx +++ b/tests/run/enumerate_T316.pyx @@ -12,7 +12,7 @@ def go_py_enumerate(): for i,k in enumerate(range(1,5)): print i, k -#T442 @cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']") +@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']") def go_c_enumerate(): """ >>> go_c_enumerate() @@ -25,7 +25,7 @@ def go_c_enumerate(): for i,k in enumerate(range(1,5)): print i, k -#T442 @cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']") +@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']") def go_c_enumerate_step(): """ >>> go_c_enumerate_step() @@ -97,7 +97,7 @@ def py_enumerate_continue(*t): continue print u"::", i, k -# T442 @cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']") +@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']") def empty_c_enumerate(): """ >>> empty_c_enumerate() @@ -132,7 +132,7 @@ def multi_enumerate(): for a,(b,(c,d)) in enumerate(enumerate(enumerate(range(1,5)))): print a,b,c,d -# T442 @cython.test_fail_if_path_exists("//SimpleCallNode") +@cython.test_fail_if_path_exists("//SimpleCallNode") def multi_c_enumerate(): """ >>> multi_c_enumerate() @@ -145,7 +145,7 @@ def multi_c_enumerate(): for a,(b,(c,d)) in enumerate(enumerate(enumerate(range(1,5)))): print a,b,c,d -# T442 @cython.test_fail_if_path_exists("//SimpleCallNode") +@cython.test_fail_if_path_exists("//SimpleCallNode") def convert_target_enumerate(L): """ >>> convert_target_enumerate([2,3,5])