avoid redundant initialisation of closure variables with None/NULL
authorStefan Behnel <scoder@users.berlios.de>
Thu, 30 Apr 2009 15:15:44 +0000 (17:15 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 30 Apr 2009 15:15:44 +0000 (17:15 +0200)
Cython/Compiler/ModuleNode.py
Cython/Compiler/Nodes.py
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/Symtab.py

index 1fe75c5e33f47e6beb77974f2d9fde381ef15235..028661e63120d8c59711f4d9dfcbe8f22e80c502 100644 (file)
@@ -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)
index 7f611afc6c68641fff5b4a4a4ee4736f3966efd6..a3f1adb1b6d43a85cee7b768f8393e8a4898da33 100644 (file)
@@ -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(''),
index f23568542b721c3102c300abc1427d402dec7d19..d2bc9b7305f5c4c4ef3ae1362a77bb4344cc5cea 100644 (file)
@@ -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?
index b1a361eefa40f6ca4c0f361f017998dc7911e3d5..4be5818a660332182af3db7b331a0e8d9dfa4f09 100644 (file)
@@ -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