[Cython] cython leaks references to Py_None for cdef'ed globals

Lisandro Dalcin dalcinl at gmail.com
Wed Oct 1 20:19:53 CEST 2008


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 <dalcinl at gmail.com> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fixinitnoneleaks.diff
Type: text/x-patch
Size: 1166 bytes
Desc: not available
Url : http://codespeak.net/pipermail/cython-dev/attachments/20081001/8c5e15b7/attachment.bin 


More information about the Cython-dev mailing list