From 62567a26cce712fc1099c49bb02a8cc49ef462fc Mon Sep 17 00:00:00 2001 From: Vitja Makarov Date: Wed, 30 Mar 2011 21:28:04 +0200 Subject: [PATCH] Handle generic declared args inside closure --- Cython/Compiler/ModuleNode.py | 11 +++++++++-- Cython/Compiler/ParseTreeTransforms.py | 4 +++- Cython/Compiler/Symtab.py | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 8a863914..f94c47f6 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -942,9 +942,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): type.vtabstruct_cname, type.vtabslot_cname)) for attr in type.scope.var_entries: + if attr.is_declared_generic: + attr_type = py_object_type + else: + attr_type = attr.type code.putln( "%s;" % - attr.type.declaration_code(attr.cname)) + attr_type.declaration_code(attr.cname)) code.putln(footer) if type.objtypedef_cname is not None: # Only for exposing public typedef name. @@ -1241,7 +1245,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): for entry in py_attrs: name = "p->%s" % entry.cname code.putln("tmp = ((PyObject*)%s);" % name) - code.put_init_to_py_none(name, entry.type, nanny=False) + if entry.is_declared_generic: + code.put_init_to_py_none(name, py_object_type, nanny=False) + else: + code.put_init_to_py_none(name, entry.type, nanny=False) code.putln("Py_XDECREF(tmp);") code.putln( "return 0;") diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 0dbca654..11bef00d 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -1636,11 +1636,13 @@ class CreateClosureClasses(CythonTransform): is_cdef=True) node.needs_outer_scope = True for name, entry in in_closure: - class_scope.declare_var(pos=entry.pos, + closure_entry = class_scope.declare_var(pos=entry.pos, name=entry.name, cname=entry.cname, type=entry.type, is_cdef=True) + if entry.is_declared_generic: + closure_entry.is_declared_generic = 1 node.needs_closure = True # Do it here because other classes are already checked target_module_scope.check_c_class(func_scope.scope_class) diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index a74260f6..02c5c54e 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -1331,6 +1331,7 @@ class LocalScope(Scope): inner_entry.is_variable = True inner_entry.outer_entry = entry inner_entry.from_closure = True + inner_entry.is_declared_generic = entry.is_declared_generic self.entries[name] = inner_entry return inner_entry return entry -- 2.26.2