[Python-3000] int-long unification

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Mon Aug 21 13:11:12 CEST 2006


Nick Coghlan <ncoghlan at gmail.com> writes:

> PyInt_AsLong can already fail with OverflowError

> it accepts arbitrary objects and coerces them to integers via
> __int__, instead of just accepting PyInt instances.

If it calls __int__, it can fail with any exception resulting from
user code.

Grepping sources (2.4.2) reveals that usages are split into 4 groups:

1. Calling PyInt_AsLong only after PyInt_Check succeeds.

2. Handling the case when PyInt_AsLong returns -1 and PyErr_Occurred(),
   or just when PyErr_Occurred().

3. Doing both (e.g. Modules/mmapmodule.c). The test is superfluous
   but harmless.

4. Doing neither (e.g. Modules/parsermodule.c, Modules/posixmodule.c,
   Modules/selectmodule.c and possibly more). This is potentially buggy.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


More information about the Python-3000 mailing list