You have attached three different patches fixing this in different ways. But I really believe the #3 is the best, safest one.
You also have a small pyx file in orther you can easily spot the geneated code and the behavior of patch #3. WARNING: You have to generate C sources and test with $ cython --cleanup 9 modglbinit.pyx $ <gcc modglbinit,c -> modglbinit.so> $ python -c 'import modglb' This example is vile hackery, and SHOULD NOT be included in the testsuite right now (unless the testsuite generates C sources with --cleanup options?). Perhaps if --cleanup could be passed as a directive, then it could go in. On Thu, Oct 9, 2008 at 7:15 PM, Robert Bradshaw <[EMAIL PROTECTED]> wrote: > > On Oct 3, 2008, at 9:29 PM, Lisandro Dalcin wrote: > >> OK, at this link http://publications.gbdirect.co.uk/c_book/chapter8/ >> typedef.html >> >> I've found the following example: >> >> /* >> * Using typedef, declare 'func' to have type >> * 'function taking two int arguments, returning int' >> */ >> typedef int func(int, int); >> /* ERROR */ >> func func_name{ /*....*/ } >> /* Correct. Returns pointer to a type 'func' */ >> func *func_name(){ /*....*/ } >> /* >> * Correct if functions could return functions, >> * but C can't. >> */ >> func func_name(){ /*....*/ } >> >> >> I'm fine with that. So I´ll try tomorrow if Robert´s modifications can >> handle this form. Thank's for the point, Greg! >> > > Lisandro, > > What was the final resolution on this? > > - Robert > > > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594
diff -r 234d7128643b Cython/Compiler/ModuleNode.py
--- a/Cython/Compiler/ModuleNode.py Wed Oct 08 02:22:20 2008 -0700
+++ b/Cython/Compiler/ModuleNode.py Wed Oct 08 13:54:07 2008 -0300
@@ -1634,7 +1634,7 @@ class ModuleNode(Nodes.Node, Nodes.Block
for entry in rev_entries:
if entry.visibility != 'extern':
if entry.type.is_pyobject:
- code.put_var_decref_clear(entry)
+ code.put_var_xdecref_clear(entry)
if Options.generate_cleanup_code >= 3:
code.putln("/*--- Type import cleanup code ---*/")
for type, _ in env.types_imported.items():
@@ -1735,7 +1735,11 @@ class ModuleNode(Nodes.Node, Nodes.Block
for entry in env.var_entries:
if entry.visibility != 'extern':
if entry.type.is_pyobject:
- code.put_init_var_to_py_none(entry)
+ if entry.init_to_none is False:
+ code.putln("%s = 0;" % entry.cname)
+ else:
+ code.put_init_var_to_py_none(entry)
+
def generate_c_function_export_code(self, env, code):
# Generate code to create PyCFunction wrappers for exported C functions.
diff -r 234d7128643b Cython/Compiler/Optimize.py
--- a/Cython/Compiler/Optimize.py Wed Oct 08 02:22:20 2008 -0700
+++ b/Cython/Compiler/Optimize.py Wed Oct 08 14:31:02 2008 -0300
@@ -152,7 +152,9 @@ class FinalOptimizePhase(Visitor.CythonT
def visit_SingleAssignmentNode(self, node):
if node.first:
lhs = node.lhs
- if isinstance(lhs, ExprNodes.NameNode) and lhs.entry.type.is_pyobject:
+ if isinstance(lhs, ExprNodes.NameNode) and \
+ lhs.entry.type.is_pyobject and \
+ not lhs.entry.scope.is_module_scope:
# Have variable initialized to 0 rather than None
lhs.entry.init_to_none = False
lhs.entry.init = 0
diff -r 234d7128643b Cython/Compiler/Optimize.py
--- a/Cython/Compiler/Optimize.py Wed Oct 08 02:22:20 2008 -0700
+++ b/Cython/Compiler/Optimize.py Wed Oct 08 18:16:16 2008 -0300
@@ -153,11 +153,12 @@ class FinalOptimizePhase(Visitor.CythonT
if node.first:
lhs = node.lhs
if isinstance(lhs, ExprNodes.NameNode) and lhs.entry.type.is_pyobject:
- # Have variable initialized to 0 rather than None
- lhs.entry.init_to_none = False
lhs.entry.init = 0
- # Set a flag in NameNode to skip the decref
- lhs.skip_assignment_decref = True
+ if not lhs.entry.scope.is_module_scope:
+ # Have variable initialized to 0 rather than None
+ lhs.entry.init_to_none = False
+ # Set a flag in NameNode to skip the decref
+ lhs.skip_assignment_decref = True
return node
def visit_SimpleCallNode(self, node):
modglbinit.pyx
Description: Binary data
_______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
