[Cython] Bug in NULL handling introduced 0.14.1-1

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Feb 14 07:50:03 CET 2011

Chris Colbert wrote:
> changing the include definition to:
> cdef extern from "Python.h":
>      int PyObject_GenericSetAttr(PyObject*, PyObject*, PyObject*) except -1

This suggests another possible workaround:

   cdef extern from "Python.h":
     int PyObject_GenericDelAttr "PyObject_GenericSetAttr" (object, object, 

This creates an alias for PyObject_GenericSetAttr with a different
signature, which you then call as

   PyObject_GenericDelAttr(obj, name, NULL)

If you're willing to write a tiny bit of C, you could make this tidier
by using a .h file containing

#define PyObject_GenericDelAttr(obj, name) PyObject_GenericSetAttr(obj, name, NULL)

and then declare PyObject_GenericDelAttr to Cython with just two

Maybe Cython should include something like this in its standard preamble,
along with similar macros for other NULL-taking API functions.


More information about the cython-devel mailing list