From: <ti...@co...> - 2008-12-16 00:53:47
|
Author: tismer Date: Tue Dec 16 01:54:49 2008 New Revision: 60504 Modified: psyco/dist/c/Objects/pabstract.c psyco/dist/c/Objects/plongobject.c Log: fixed long_pow for negative exponents. This is the oldest bug in psyco that I can imagine, since it existed before psyco's invention :-) Modified: psyco/dist/c/Objects/pabstract.c ============================================================================== --- psyco/dist/c/Objects/pabstract.c (original) +++ psyco/dist/c/Objects/pabstract.c Tue Dec 16 01:54:49 2008 @@ -806,6 +806,7 @@ f = PyFloat_Type.tp_as_number->nb_power; else if (vtp == &PyLong_Type || wtp == &PyLong_Type) f = PyLong_Type.tp_as_number->nb_power; + /* note this subpath had an error since 2001 */ else f = PyInt_Type.tp_as_number->nb_power; x = Psyco_META3(po, f, CfReturnRef|CfPyErrIfNull, Modified: psyco/dist/c/Objects/plongobject.c ============================================================================== --- psyco/dist/c/Objects/plongobject.c (original) +++ psyco/dist/c/Objects/plongobject.c Tue Dec 16 01:54:49 2008 @@ -64,7 +64,15 @@ #endif RETLONG(2, plong_classic_div, nb_divide) RETLONG(2, plong_mod, nb_remainder) -RETLONG(3, plong_pow, nb_power) + +/* + note that psyco's assumption about the return type of long_pow + was wrong from the beginning. Since Python 2.2, or even more exact + since rev. 21646, July 12 2001 by Guido, long_pow can return + a float for negative exponents. + RETLONG(3, plong_pow, nb_power) + */ + RETLONG(1, plong_neg, nb_negative) RETLONG(1, plong_pos, nb_positive) RETLONG(1, plong_abs, nb_absolute) @@ -79,6 +87,16 @@ #undef RETLONG +static vinfo_t* plong_pow(PsycoObject *po, vinfo_t* v1, vinfo_t* v2, + vinfo_t* v3) +{ + /* this version is identical to the macros above, but + does not assert the return type. (cf. DEF_KNOWN_RET_TYPE_internal + in pobject.h) */ + return psyco_generic_call(po, PyLong_Type.tp_as_number->nb_power, + CfReturnRef|CfPyErrNotImplemented, + "vvv", v1, v2, v3); +} INITIALIZATIONFN void psy_longobject_init(void) |