comments, code cleanup
authorStefan Behnel <scoder@users.berlios.de>
Tue, 14 Dec 2010 06:28:17 +0000 (07:28 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 14 Dec 2010 06:28:17 +0000 (07:28 +0100)
Cython/Compiler/ExprNodes.py
Cython/Compiler/Nodes.py

index e46b95212ccf684a6c9c738843705ff19f131019..ab31ec6c7c59736226f708c62340bc523f3db6b5 100755 (executable)
@@ -5007,27 +5007,30 @@ class YieldExprNode(ExprNode):
             code.put_init_to_py_none(Naming.retval_cname, py_object_type)
         saved = []
         code.temp_allocator.reset()
-        code.putln('/* Save temporary variables */')
-        for cname, type, manage_ref in code.funcstate.temps_in_use():
-            save_cname = code.temp_allocator.allocate_temp(type)
-            saved.append((cname, save_cname, type))
-            if type.is_pyobject:
-                code.put_xgiveref(cname)
-            code.putln('%s->%s = %s;' % (Naming.cur_scope_cname, save_cname, cname))
+        temps_in_use = code.funcstate.temps_in_use()
+        if temps_in_use:
+            code.putln('/* Save temporary variables */')
+            for cname, type, manage_ref in temps_in_use:
+                save_cname = code.temp_allocator.allocate_temp(type)
+                saved.append((cname, save_cname, type))
+                if type.is_pyobject:
+                    code.put_xgiveref(cname)
+                code.putln('%s->%s = %s;' % (Naming.cur_scope_cname, save_cname, cname))
 
         code.put_xgiveref(Naming.retval_cname)
         code.put_finish_refcount_context()
-        code.putln("/* return from function, yielding value */")
+        code.putln("/* return from generator, yielding value */")
         code.putln("%s->%s.resume_label = %d;" % (Naming.cur_scope_cname, Naming.obj_base_cname, self.label_num))
         code.putln("return %s;" % Naming.retval_cname);
         code.put_label(self.label_name)
-        code.putln('/* Restore temporary variables */')
-        for cname, save_cname, type in saved:
-            code.putln('%s = %s->%s;' % (cname, Naming.cur_scope_cname, save_cname))
-            if type.is_pyobject:
-                code.putln('%s->%s = 0;' % (Naming.cur_scope_cname, save_cname))
-            if type.is_pyobject:
-                code.put_xgotref(cname)
+        if saved:
+            code.putln('/* Restore temporary variables */')
+            for cname, save_cname, type in saved:
+                code.putln('%s = %s->%s;' % (cname, Naming.cur_scope_cname, save_cname))
+                if type.is_pyobject:
+                    code.putln('%s->%s = 0;' % (Naming.cur_scope_cname, save_cname))
+                if type.is_pyobject:
+                    code.put_xgotref(cname)
         if self.result_is_used:
             self.allocate_temp_result(code)
             code.putln('%s = %s; %s' %
index d3443036257171bb4fc1cfcb9f3108d782a95730..3ddfad0761e21c0a04081752b5d6c77dcfcf6315 100644 (file)
@@ -1510,7 +1510,7 @@ class FuncDefNode(StatNode, BlockNode):
             resume_code.putln("case 0: goto %s;" % first_run_label)
             for yield_expr in self.yields:
                 resume_code.putln("case %d: goto %s;" % (yield_expr.label_num, yield_expr.label_name));
-            resume_code.putln("default: /* raise error here */");
+            resume_code.putln("default: /* CPython raises the right error here */");
             resume_code.putln("return NULL;");
             resume_code.putln("}");
         # ----- Python version