[Python-3000] PyInt_AS_LONG error checking

"Martin v. Löwis" martin at v.loewis.de
Tue Oct 23 21:03:54 CEST 2007


> PyInt_AS_LONG is #defined as PyLong_AsLong since the int/long unification.
> 
> However, most places that use this macro (and also places that
> use PyInt_AsLong) assume it cannot fail which means that an exception
> won't be properly propagated in that case.
> 
> If I don't overlook something here, all these places have to be fixed...

I think you do overlook something. Many of these places do
PyInt_CheckExact before invoking the macro. PyInt_CheckExact includes
_PyLong_FitsInLong, so if that test returns true, then PyInt_AS_LONG
cannot fail.

So the only places that need to be fixed are those where PyInt_AS_LONG
isn't protected by PyInt_CheckExact.

HTH,
Martin


More information about the Python-3000 mailing list