[Cython] Bug in NULL handling introduced 0.14.1-1

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Feb 13 21:31:30 CET 2011

Chris Colbert wrote:
> I have cython file which is using PyObject_GenericSetAttr 
> Now in my script I am using that function to generically delete an 
> attribute by passing a NULL as the last value (this is proper way to 
> trigger a generic delattr in the Python c-api)

I would have thought the proper way to do that was to use
PyObject_DelAttr, which Pyrex exposes as delattr().

I don't think PyObject_GenericSetAttr is even meant to be
called directly -- it's intended for filling the tp_setattr
slot of type objects.

> This causes a segfault because the NULL is getting increfed via 
> Py_INCREF instead of Py_XINCREF.

I would recommend against trying to "fix" this. You got
away with it before because you happened to be passing the
NULL value directly to a function which is expecting it.
But casting NULL to an object reference is not something
that should be encouraged, because in any other context it
would quickly lead to disaster.


More information about the cython-devel mailing list