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