cython-devel

changeset 1241:b23f31007194

fix the declaration/initilization/cleanup of module global cdef Python objects
author Lisandro Dalcin <dalcinl@gmail.com>
date Thu Oct 16 20:26:34 2008 -0300 (4 years ago)
parents 57467649c34c
children e597dcac63ac
files Cython/Compiler/ModuleNode.py Cython/Compiler/ParseTreeTransforms.py Cython/Compiler/Symtab.py tests/compile/globvardef.pyx
line diff
1.1 --- a/Cython/Compiler/ModuleNode.py Wed Oct 15 12:10:09 2008 -0300 1.2 +++ b/Cython/Compiler/ModuleNode.py Thu Oct 16 20:26:34 2008 -0300 1.3 @@ -1633,7 +1633,7 @@ 1.4 rev_entries.reverse() 1.5 for entry in rev_entries: 1.6 if entry.visibility != 'extern': 1.7 - if entry.type.is_pyobject: 1.8 + if entry.type.is_pyobject and entry.used: 1.9 code.put_var_decref_clear(entry) 1.10 if Options.generate_cleanup_code >= 3: 1.11 code.putln("/*--- Type import cleanup code ---*/") 1.12 @@ -1734,7 +1734,7 @@ 1.13 # variables to None. 1.14 for entry in env.var_entries: 1.15 if entry.visibility != 'extern': 1.16 - if entry.type.is_pyobject: 1.17 + if entry.type.is_pyobject and entry.used: 1.18 code.put_init_var_to_py_none(entry) 1.19 1.20 def generate_c_function_export_code(self, env, code):
2.1 --- a/Cython/Compiler/ParseTreeTransforms.py Wed Oct 15 12:10:09 2008 -0300 2.2 +++ b/Cython/Compiler/ParseTreeTransforms.py Thu Oct 16 20:26:34 2008 -0300 2.3 @@ -183,9 +183,10 @@ 2.4 handler(decl) 2.5 continue # Remove declaration 2.6 raise PostParseError(decl.pos, ERR_CDEF_INCLASS) 2.7 + first_assignment = self.scope_type != 'module' 2.8 stats.append(SingleAssignmentNode(node.pos, 2.9 lhs=NameNode(node.pos, name=declbase.name), 2.10 - rhs=declbase.default, first=True)) 2.11 + rhs=declbase.default, first=first_assignment)) 2.12 declbase.default = None 2.13 newdecls.append(decl) 2.14 node.declarators = newdecls
3.1 --- a/Cython/Compiler/Symtab.py Wed Oct 15 12:10:09 2008 -0300 3.2 +++ b/Cython/Compiler/Symtab.py Thu Oct 16 20:26:34 2008 -0300 3.3 @@ -934,6 +934,8 @@ 3.4 entry.is_pyglobal = 1 3.5 else: 3.6 entry.is_cglobal = 1 3.7 + if entry.type.is_pyobject: 3.8 + entry.init = 0 3.9 self.var_entries.append(entry) 3.10 return entry 3.11
4.1 --- a/tests/compile/globvardef.pyx Wed Oct 15 12:10:09 2008 -0300 4.2 +++ b/tests/compile/globvardef.pyx Thu Oct 16 20:26:34 2008 -0300 4.3 @@ -2,4 +2,6 @@ 4.4 cdef a_global_pyobject 4.5 4.6 a_global_int = 0 4.7 -a_global_pyobject = None 4.8 \ No newline at end of file 4.9 +a_global_pyobject = None 4.10 + 4.11 +cdef object unused