Commit e2f43afd authored by Lisandro Dalcin's avatar Lisandro Dalcin

fix the declaration/initilization/cleanup of module global cdef Python objects

parent 94b89da9
......@@ -1633,7 +1633,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
rev_entries.reverse()
for entry in rev_entries:
if entry.visibility != 'extern':
if entry.type.is_pyobject:
if entry.type.is_pyobject and entry.used:
code.put_var_decref_clear(entry)
if Options.generate_cleanup_code >= 3:
code.putln("/*--- Type import cleanup code ---*/")
......@@ -1734,7 +1734,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# variables to None.
for entry in env.var_entries:
if entry.visibility != 'extern':
if entry.type.is_pyobject:
if entry.type.is_pyobject and entry.used:
code.put_init_var_to_py_none(entry)
def generate_c_function_export_code(self, env, code):
......
......@@ -183,9 +183,10 @@ class PostParse(CythonTransform):
handler(decl)
continue # Remove declaration
raise PostParseError(decl.pos, ERR_CDEF_INCLASS)
first_assignment = self.scope_type != 'module'
stats.append(SingleAssignmentNode(node.pos,
lhs=NameNode(node.pos, name=declbase.name),
rhs=declbase.default, first=True))
rhs=declbase.default, first=first_assignment))
declbase.default = None
newdecls.append(decl)
node.declarators = newdecls
......
......@@ -934,6 +934,8 @@ class ModuleScope(Scope):
entry.is_pyglobal = 1
else:
entry.is_cglobal = 1
if entry.type.is_pyobject:
entry.init = 0
self.var_entries.append(entry)
return entry
......
......@@ -2,4 +2,6 @@ cdef int a_global_int
cdef a_global_pyobject
a_global_int = 0
a_global_pyobject = None
\ No newline at end of file
a_global_pyobject = None
cdef object unused
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