[Pyrex] Missing Py_DECREF in generated code

Igor Khavkine igor.kh at gmail.com
Thu Nov 30 16:49:48 UTC 2006


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.

Thanks.

Igor



More information about the Pyrex mailing list