patch cleanup and test fix (avoid uninitialised variable)
authorStefan Behnel <scoder@users.berlios.de>
Fri, 20 Mar 2009 16:51:46 +0000 (17:51 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 20 Mar 2009 16:51:46 +0000 (17:51 +0100)
--HG--
rename : tests/bugs/rangeOptimization_T203.pyx => tests/run/range_optimisation_T203.pyx

Cython/Compiler/Nodes.py
tests/run/range_optimisation_T203.pyx [moved from tests/bugs/rangeOptimization_T203.pyx with 97% similarity]

index 757055f7c1c43c1eabcabf1b7130363a8fe2a3ef..9c213a108eae52de7b38dfe1d60ca2b3e640f12f 100644 (file)
@@ -3967,26 +3967,21 @@ class ForFromStatNode(LoopNode, StatNode):
             decop = "%s=%s" % (decop[0], step)
         loopvar_name = self.loopvar_node.result()
         if from_range:
-            temp_range_bound = code.funcstate.allocate_temp(self.bound2.type, manage_ref=False)
-            code.putln("%s = %s;" % (temp_range_bound, self.bound2.result()))
+            range_bound = code.funcstate.allocate_temp(self.bound2.type, manage_ref=False)
+            code.putln("%s = %s;" % (range_bound, self.bound2.result()))
             # Skip the loop entirely (and avoid assigning to the loopvar) if
             # the loop is empty:
             code.putln("if (%s%s %s %s) {" % (
-            self.bound1.result(), offset, self.relation2, temp_range_bound
-            ))
-            code.putln(
-                "for (%s = %s%s; %s %s %s; %s%s) {" % (
-                    loopvar_name,
-                    self.bound1.result(), offset,
-                    loopvar_name, self.relation2, temp_range_bound,
-                    loopvar_name, incop))
+                self.bound1.result(), offset, self.relation2, range_bound
+                ))
         else:
-            code.putln(
-                "for (%s = %s%s; %s %s %s; %s%s) {" % (
-                    loopvar_name,
-                    self.bound1.result(), offset,
-                    loopvar_name, self.relation2, self.bound2.result(),
-                    loopvar_name, incop))
+            range_bound = self.bound2.result()
+        code.putln(
+            "for (%s = %s%s; %s %s %s; %s%s) {" % (
+                loopvar_name,
+                self.bound1.result(), offset,
+                loopvar_name, self.relation2, range_bound,
+                loopvar_name, incop))
         if self.py_loopvar_node:
             self.py_loopvar_node.generate_evaluation_code(code)
             self.target.generate_assignment_code(self.py_loopvar_node, code)
@@ -3997,7 +3992,7 @@ class ForFromStatNode(LoopNode, StatNode):
             code.putln("} %s%s;" % (loopvar_name, decop))
             # End the outer if statement:
             code.putln("} /* end if */")
-            code.funcstate.release_temp(temp_range_bound)
+            code.funcstate.release_temp(range_bound)
         else:
             code.putln("}")
         break_label = code.break_label
similarity index 97%
rename from tests/bugs/rangeOptimization_T203.pyx
rename to tests/run/range_optimisation_T203.pyx
index 3388c2d07b1d85e9bc7112998245fdde19332e03..5ae5e9511181c02b2cf8daa7aa9fc446ac4da1c6 100644 (file)
@@ -53,7 +53,7 @@ cdef int g():
     return 3
 
 def f():
-    cdef int i
+    cdef int i = -1
     for i in range(g()):
         print i
     print i