From: Vitja Makarov Date: Sun, 9 Jan 2011 11:02:48 +0000 (+0300) Subject: Don't store yield expressions list as yields can be copied X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=429284038955ed9f67e2068534a3eb6d79922a97;p=cython.git Don't store yield expressions list as yields can be copied --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 8aedbde4..01ce116d 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -2944,11 +2944,10 @@ class GeneratorBodyDefNode(DefNode): child_attrs = ["args", "star_arg", "starstar_arg", "body", "decorators"] - def __init__(self, pos=None, name=None, body=None, yields=None): + def __init__(self, pos=None, name=None, body=None): super(GeneratorBodyDefNode, self).__init__(pos=pos, body=body, name=name, doc=None, args=[], star_arg=None, starstar_arg=None) - self.yields = yields def declare_generator_body(self, env): prefix = env.next_id(env.scope_prefix) @@ -3030,7 +3029,11 @@ class GeneratorBodyDefNode(DefNode): # ----- Generator resume code resume_code.putln("switch (%s->%s.resume_label) {" % (Naming.cur_scope_cname, Naming.obj_base_cname)); resume_code.putln("case 0: goto %s;" % first_run_label) - for yield_expr in self.yields: + + from ParseTreeTransforms import YieldNodeCollector + collector = YieldNodeCollector() + collector.visitchildren(self) + for yield_expr in collector.yields: resume_code.putln("case %d: goto %s;" % (yield_expr.label_num, yield_expr.label_name)); resume_code.putln("default: /* CPython raises the right error here */"); resume_code.put_finish_refcount_context() diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index dd038388..aeb2c65f 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -1332,7 +1332,6 @@ class YieldNodeCollector(TreeVisitor): if self.has_return_value: error(node.pos, "'yield' outside function") self.yields.append(node) - node.label_num = len(self.yields) def visit_ReturnStatNode(self, node): if node.value: @@ -1370,10 +1369,12 @@ class MarkClosureVisitor(CythonTransform): collector.visitchildren(node) if collector.yields: + for i, yield_expr in enumerate(collector.yields): + yield_expr.label_num = i + 1 + gbody = Nodes.GeneratorBodyDefNode(pos=node.pos, name=node.name, - body=node.body, - yields=collector.yields) + body=node.body) generator = Nodes.GeneratorDefNode(pos=node.pos, name=node.name, args=node.args,