[Python-Dev] PyInt_AsSsize_t on x64

Armin Rigo arigo at tunes.org
Sat May 5 12:55:18 CEST 2007

Hi Kristján,

On Thu, May 03, 2007 at 03:57:26PM +0000, Kristján Valur Jónsson wrote:
>       if (nb->nb_long != 0) {
>             io = (PyIntObject*) (*nb->nb_long) (op);
>       } else {
>             io = (PyIntObject*) (*nb->nb_int) (op);
>       }

> Now, how to fix this?  Should the code in intobject.c catch the
> AttributeError, maybe, and continue to the nb_int?

The problem is specific to old-style classes: in principle, only them
have all slots non-null even if they don't really define the
corresponding special methods.  With anything else than old-style
classes you don't get an AttributeError if a special method doesn't
exist, which makes checking for AttributeError in PyInt_AsSsize_t()

Given that the __long__ vs __int__ difference doesn't really make sense
any more nowadays, I'd think it would be saner to change the nb_long
slot of old-style instances instead of PyInt_AsSsize_t().  The logic
would be that if the nb_long slot implementation finds no "__long__"
attribute on the instance it tries with "__int__" instead.

A bientot,


More information about the Python-Dev mailing list