BTW, this patch fix the issue by not initializing cdef'ed module
globals to None. But this is not the safest approach (I can imagine
some nasty ways to originate segfaults). Perhaps we should try to fix
the isue in FinalOptimizePhase.visit_SingleAssignmentNode

On Wed, Oct 1, 2008 at 3:13 PM, Lisandro Dalcin <[EMAIL PROTECTED]> wrote:
> Consider the following code inside a one-line pyx file:
>
> cdef object someint = 7
>
> Then Cython generates the following inside the module init function:
>
>  /*--- Global init code ---*/
>  __pyx_v_9refleaks2_someint = Py_None; Py_INCREF(Py_None);
>
>  /* "/u/dalcinl/Devel/Cython/sandbox/refleaks2.pyx":1
>  * cdef object someint = 7             # <<<<<<<<<<<<<<
>  *
>  */
>  Py_INCREF(__pyx_int_7);
>  __pyx_v_9refleaks2_someint = __pyx_int_7;
>
>
> Clearly, Py_None references are being leaked. All this is because of
> bad interaction between this two methods:
>
> * ModuleNode.generate_global_init_code(...) (in ModuleNode.py)
> * FinalOptimizePhase.visit_SingleAssignmentNode(...) (in Optimize.py)
>
>
>
> --
> 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
>



-- 
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 d065589d0191 Cython/Compiler/ModuleNode.py
--- a/Cython/Compiler/ModuleNode.py	Tue Sep 30 13:12:52 2008 -0700
+++ b/Cython/Compiler/ModuleNode.py	Wed Oct 01 15:15:47 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,8 @@ 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:
+                        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.
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to