[Python-checkins] python/dist/src/Objects intobject.c,2.79.6.2,2.79.6.3

nascheme@users.sourceforge.net nascheme@users.sourceforge.net
Fri, 09 Aug 2002 08:46:52 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv31698/Objects

Modified Files:
      Tag: release22-maint
	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.79.6.2
retrieving revision 2.79.6.3
diff -C2 -d -r2.79.6.2 -r2.79.6.3
*** intobject.c	26 Apr 2002 06:31:22 -0000	2.79.6.2
--- intobject.c	9 Aug 2002 15:46:50 -0000	2.79.6.3
***************
*** 345,348 ****
--- 345,354 ----
  */
  
+ /* 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)
***************
*** 353,366 ****
  	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);
--- 359,368 ----
  	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);