[Python-Dev] Bug in PyNumber_InPlacePower implementation?
Greg Ewing
greg@cosc.canterbury.ac.nz
Wed, 29 May 2002 11:48:19 +1200 (NZST)
I was looking at the implementation of PyNumber_InPlacePower last
night, and something about it struck me as odd. It starts off:
if (HASINPLACE(v) && v->ob_type->tp_as_number &&
v->ob_type->tp_as_number->nb_inplace_power != NULL) {
return ternary_op(v, w, z, NB_SLOT(nb_inplace_power), "**=");
Now, looking at ternary_op, it appears that under some
circumstances this could call the nb_inplace_power slot
of the second or third argument before trying the first
one:
if (slotv) {
if (slotw && PyType_IsSubtype(w->ob_type, v->ob_type)) {
x = slotw(v, w, z);
i.e. if the 2nd argument is a subtype of the 1st, and it
has an nb_inplace_power method, it will be called first.
This looks wrong to me. Surely only the *first* argument
should be checked for an inplace method when doing an
inplace operation? That's the way it seems to be for
all the other inplace operations. Is this a bug?
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg@cosc.canterbury.ac.nz +--------------------------------------+