Undocumented Python 2.6 change: Py_None vs NULL when C implementation raises exception

Heikki Toivonen heikki at osafoundation.org
Wed Jul 23 20:42:38 CEST 2008


I was debugging M2Crypto function written in C which changed behavior
between Python 2.6 and earlier Python versions. In an error condition
the function was supposed to raise exception type A, but with 2.6 it
raised type B, and further, there was no string value for the exception.

I tracked this down to the C code incorrectly returning Py_None when it
should have returned NULL. Changing the C code to return NULL made it
behave correctly in 2.6.

I don't know how common a mistake it is to return Py_None when NULL
should have been returned, but it might be worth a note in the list of
changes for 2.6 that this behavior changed, don't you think?

-- 
  Heikki Toivonen



More information about the Python-list mailing list