[Pyrex] Missing Py_DECREF in generated code

William Stein wstein at gmail.com
Thu Nov 30 17:17:51 UTC 2006


On Thu, 30 Nov 2006 08:49:48 -0800, Igor Khavkine <igor.kh at gmail.com>  
wrote:

> I've recently run into the following bug in Pyrex's code generation.
> Consider the following .pyx file:
>
> ---- bug.pyx ----
> cdef class T:
> 	cdef int i
> 	cdef int j
> 	cdef int a[1]
>
> cdef void leak (void *obj):
> 	cdef T t
> 	(<T> obj).j = 1
> 	(<T> obj).i = (<T> obj).i + 1
> 	(<T> obj).a[0] = (<T> obj).a[0] + 1   # <-- Missing Py_DECREF
> 	t = <T> obj
> 	t.a[0] = t.a[0] + 1
> -----------------
>
> The C code generated by Pyrex 0.9.3 lacks a Py_DECREF at the place of
> the indicated line. Thus, every time the function leak() is run, the
> object pointed to by obj gets an extra reference count. All the other
> lines in leak() produce correct code.
>
> Funny enough, the only way I noticed this bug when the reference counter
> on one of my objects overflowed and became negative, which caused some
> mysterious deallocations to take place when the garbage collector was
> invoked.
>
> This bug sounds similar in spirit to the one reported by Jonathan Doda,
> which is marked fixed in the 0.9.4 release notes. However, I have not
> tested with that version and am not sure whether that fix also applies
> to this bug.

I just tested your example with what I think is the latest version
of Pyrex with all patches I know of applied, and the bug is definitely
still there.  You can try it all out interactively on this web
page:   http://modular.math.washington.edu:8101/leak

I've posted this as a bug on the SAGE trac server:

    http://sage.math.washington.edu:9002/sage_trac/ticket/172

(since pyrex doesn't have a bug tracker, as far as I know...)
If you search for "pyrex" or "sagex" in the above tracker,
you'll get a bunch of pyrex related things.

Anybody on this list that knows of Pyrex bugs should feel
free to send them to me or post them to the tracker (I have
to create an account for you -- email me with a login).

william



More information about the Pyrex mailing list