From: Stefan Behnel Date: Thu, 30 Apr 2009 15:15:44 +0000 (+0200) Subject: avoid redundant initialisation of closure variables with None/NULL X-Git-Tag: 0.13.beta0~2^2~148 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ad049a21fbb76773c45a04c101cef0a8f632256c;p=cython.git avoid redundant initialisation of closure variables with None/NULL --- diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 1fe75c5e..028661e6 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -901,7 +901,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): type.vtabslot_cname, struct_type_cast, type.vtabptr_cname)) for entry in py_attrs: - if entry.name == "__weakref__": + if scope.is_internal or entry.name == "__weakref__": + # internal classes do not need None inits code.putln("p->%s = 0;" % entry.cname) else: code.put_init_var_to_py_none(entry, "p->%s", nanny=False) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 7f611afc..a3f1adb1 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1063,17 +1063,8 @@ class FuncDefNode(StatNode, BlockNode): Naming.empty_tuple)) # TODO: error handling code.put_gotref(Naming.cur_scope_cname) - # The code below is because we assume the local variables are - # innitially NULL. # Note that it is unsafe to decref the scope at this point. - for entry in lenv.arg_entries + lenv.var_entries: - if entry.in_closure and entry.type.is_pyobject: - code.put_gotref(entry.cname) # so the refnanny doesn't whine - code.put_var_decref_clear(entry) if env.is_closure_scope: - if lenv.is_closure_scope: - code.put_gotref(outer_scope_cname) - code.put_decref(outer_scope_cname, env.scope_class.type) code.putln("%s = (%s)%s;" % ( outer_scope_cname, env.scope_class.type.declaration_code(''), diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index f2356854..d2bc9b73 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -872,6 +872,7 @@ class CreateClosureClasses(CythonTransform): pos = node.pos, defining = True, implementing = True) func_scope.scope_class = entry class_scope = entry.type.scope + class_scope.is_internal = True if node.entry.scope.is_closure_scope: class_scope.declare_var(pos=node.pos, name=Naming.outer_scope_cname, # this could conflict? diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index b1a361ee..4be5818a 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -194,6 +194,7 @@ class Scope(object): # return_type PyrexType or None Return type of function owning scope # is_py_class_scope boolean Is a Python class scope # is_c_class_scope boolean Is an extension type scope + # is_closure_scope boolean # scope_prefix string Disambiguator for C names # in_cinclude boolean Suppress C declaration code # qualified_name string "modname" or "modname.classname" @@ -203,11 +204,13 @@ class Scope(object): # nogil boolean In a nogil section # directives dict Helper variable for the recursive # analysis, contains directive values. + # is_internal boolean Is only used internally (simpler setup) is_py_class_scope = 0 is_c_class_scope = 0 is_closure_scope = 0 is_module_scope = 0 + is_internal = 0 scope_prefix = "" in_cinclude = 0 nogil = 0