Commit ad049a21 authored by Stefan Behnel's avatar Stefan Behnel

avoid redundant initialisation of closure variables with None/NULL

parent 0da9830b
......@@ -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)
......
......@@ -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(''),
......
......@@ -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?
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment