
Hello there. I'm working on getting the 64 bit build of the trunk pass the testsuite. Here is one snag, that you could help me fix. In test_getargs2(), there is at line 190: self.failUnlessEqual(99, getargs_n(Long())) Now, the Long class has a __int__ method which returns 99L. However, we run into trouble here: intobject.c:210 if ((nb = op->ob_type->tp_as_number) == NULL || (nb->nb_int == NULL && nb->nb_long == 0)) { PyErr_SetString(PyExc_TypeError, "an integer is required"); return -1; } if (nb->nb_long != 0) { io = (PyIntObject*) (*nb->nb_long) (op); } else { io = (PyIntObject*) (*nb->nb_int) (op); } trouble here The trouble is that nb->nb_long is non zero, but when called, it returns an attribute error, since __long__ is missing. nb_long points to instance_long. Now, how to fix this? Should the code in intobject.c catch the AttributeError, maybe, and continue to the nb_int? Cheers, Kristján

Hi Kristján, On Thu, May 03, 2007 at 03:57:26PM +0000, Kristján Valur Jónsson wrote:
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() strange. 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, Armin.

Hi Kristján, On Thu, May 03, 2007 at 03:57:26PM +0000, Kristján Valur Jónsson wrote:
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() strange. 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, Armin.
participants (2)
-
Armin Rigo
-
Kristján Valur Jónsson