[Python-Dev] Removal of intobject.h in 3.1

"Martin v. Löwis" martin at v.loewis.de
Mon Nov 23 13:46:07 CET 2009


> In an ideal world, developers would add that code to their
> extensions right away. In the real world, where developers only
> have limited resources available, you'll get more 3.x ports
> by making such ports as painless as possible while at the
> same time not forcing them to alienate their 2.x user base.

Unfortunately, such 3.x code would be full of bugs.

>> For another example,
>>
>> long foo = PyInt_AsLong(Foo);
>>
>> has a hidden error in 3.x, with intobject: PyLong_AsLong might
>> overflow, which the 2.x case doesn't.
> 
> That's not quite true: PyInt_AsLong(obj) will try the
> nb_int slot on non-integer objects which can return errors
> (it returns -1 and sets the error message).

However, the 2.x code will typically assume that the object
is an int object, in which case PyInt_AsLong can never fail.
So with intobject.h, the code will happily compile, but then
fail to detect an exception at run-time - causing other
difficult-to-find bugs.

Regards,
Martin


More information about the Python-Dev mailing list