[Python-checkins] python/dist/src/Objects intobject.c,2.85,2.86
nascheme@users.sourceforge.net
nascheme@users.sourceforge.net
Fri, 09 Aug 2002 08:20:51 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv15244/Objects
Modified Files:
intobject.c
Log Message:
Only call sq_repeat if the object does not have a nb_multiply slot. One
example of where this changes behavior is when a new-style instance
defines '__mul__' and '__rmul__' and is multiplied by an int. Before the
change the '__rmul__' method is never called, even if the int is the
left operand.
Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.85
retrieving revision 2.86
diff -C2 -d -r2.85 -r2.86
*** intobject.c 17 Jul 2002 16:30:38 -0000 2.85
--- intobject.c 9 Aug 2002 15:20:48 -0000 2.86
***************
*** 342,345 ****
--- 342,351 ----
*/
+ /* Return true if the sq_repeat method should be used */
+ #define USE_SQ_REPEAT(o) (!PyInt_Check(o) && \
+ o->ob_type->tp_as_sequence && \
+ o->ob_type->tp_as_sequence->sq_repeat && \
+ (!o->ob_type->tp_as_number || \
+ !o->ob_type->tp_as_number->nb_multiply))
static PyObject *
int_mul(PyObject *v, PyObject *w)
***************
*** 350,363 ****
double doubleprod; /* (double)a * (double)b */
! if (!PyInt_Check(v) &&
! v->ob_type->tp_as_sequence &&
! v->ob_type->tp_as_sequence->sq_repeat) {
/* sequence * int */
a = PyInt_AsLong(w);
return (*v->ob_type->tp_as_sequence->sq_repeat)(v, a);
}
! if (!PyInt_Check(w) &&
! w->ob_type->tp_as_sequence &&
! w->ob_type->tp_as_sequence->sq_repeat) {
/* int * sequence */
a = PyInt_AsLong(v);
--- 356,365 ----
double doubleprod; /* (double)a * (double)b */
! if (USE_SQ_REPEAT(v)) {
/* sequence * int */
a = PyInt_AsLong(w);
return (*v->ob_type->tp_as_sequence->sq_repeat)(v, a);
}
! if (USE_SQ_REPEAT(w)) {
/* int * sequence */
a = PyInt_AsLong(v);