[Bf-python] checking PyInt_FromLong..
Yann Vernier
yannv at kth.se
Tue Jun 26 07:18:37 CEST 2007
On Tue, Jun 26, 2007 at 02:59:26PM +1000, Campbell Barton wrote:
> Campbell Barton wrote:
> > * Our own api code only checks around half of PyInt_FromLong, in many
> > places it just assumes it worked. and thats across the codebase.
>
> I read through the Python 2.5.1 source to see how it deals with this,
> and it only checks when PyInt_FromLong for NULL when building values
> within a loop. (a few exceptions and these may be calld from a loop)
>
> intobject.c its self returns ints without checking, this makes sense
> because returning NULL will raise an error anyway. where as setting the
> value of a list for instance wont.
Right. As is usual in the Python API, NULL returns indicate that the
exception has already been appropriately set and is a suitable return
value for your code as well *unless* you need to do cleanup. Another
reason to handle it is if you want the backtrace to show something about
C calls, but in the case of out of memory or a primitive function like
PyInt_FromLong, that's not useful.
More information about the Bf-python
mailing list