[Python-checkins] CVS: python/dist/src/Objects intobject.c,2.74,2.75 longobject.c,1.107,1.108

Guido van Rossum gvanrossum@users.sourceforge.net
Fri, 14 Sep 2001 20:14:34 -0700


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

Modified Files:
	intobject.c longobject.c 
Log Message:
A fix for SF bug #461546 (bug in long_mul).

Both int and long multiplication are changed to be more careful in
their assumptions about when one of the arguments is a sequence: the
assumption that at least one of the arguments must be an int (or long,
respectively) is still held, but the assumption that these don't smell
like sequences is no longer true: a subtype of int or long may well
have a sequence-repeat thingie!



Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.74
retrieving revision 2.75
diff -C2 -d -r2.74 -r2.75
*** intobject.c	2001/09/11 21:44:14	2.74
--- intobject.c	2001/09/15 03:14:32	2.75
***************
*** 345,356 ****
  	int s = 1;
  
! 	if (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);
  	}
! 	else if (w->ob_type->tp_as_sequence &&
! 			w->ob_type->tp_as_sequence->sq_repeat) {
  		/* int * sequence */
  		a = PyInt_AsLong(v);
--- 345,358 ----
  	int s = 1;
  
! 	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);

Index: longobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/longobject.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -C2 -d -r1.107 -r1.108
*** longobject.c	2001/09/13 19:05:30	1.107
--- longobject.c	2001/09/15 03:14:32	1.108
***************
*** 184,187 ****
--- 184,189 ----
  
  	if (vv == NULL || !PyLong_Check(vv)) {
+ 		if (vv != NULL && PyInt_Check(vv))
+ 			return PyInt_AsLong(vv);
  		PyErr_BadInternalCall();
  		return -1;
***************
*** 1449,1463 ****
  	int size_b;
  	int i;
- 	
- 	if (v->ob_type->tp_as_sequence &&
- 			v->ob_type->tp_as_sequence->sq_repeat) {
- 		return long_repeat((PyObject *)v, w);
- 	}
- 	else if (w->ob_type->tp_as_sequence &&
- 			w->ob_type->tp_as_sequence->sq_repeat) {
- 		return long_repeat((PyObject *)w, v);
- 	}
  
! 	CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
  
  	size_a = ABS(a->ob_size);
--- 1451,1467 ----
  	int size_b;
  	int i;
  
! 	if (!convert_binop((PyObject *)v, (PyObject *)w, &a, &b)) {
! 		if (!PyLong_Check(v) &&
! 		    v->ob_type->tp_as_sequence &&
! 		    v->ob_type->tp_as_sequence->sq_repeat)
! 			return long_repeat((PyObject *)v, w);
! 		if (!PyLong_Check(w) &&
! 			 w->ob_type->tp_as_sequence &&
! 			 w->ob_type->tp_as_sequence->sq_repeat)
! 			return long_repeat((PyObject *)w, v);
! 		Py_INCREF(Py_NotImplemented);
! 		return Py_NotImplemented;
! 	}
  
  	size_a = ABS(a->ob_size);