[Patches] Multiply sequences by longs
Andrew M. Kuchling
akuchlin@mems-exchange.org
Fri, 4 Feb 2000 17:06:06 -0500 (EST)
This patch makes 5L * 'b' legal; with the large-file patches, some
people have run into bugs in modules such as dumbdbm that don't expect
f.tell() to return a long int..
One inconsistency: 1231231232312341414L * 'a' gets an
OverflowError (long int too long to convert), while 312341414L * 'a'
raises a MemoryError. I think this wouldn't be a problem in practice.
Documentation: a patch to the Reference and LibRef are required; there
may be other bits of the docs that need changing. If this gets
accepted, I'll make patches for the docs.
Question: should other bits of the core be changed to accept long
ints? Slicing, for instance, as in mylist[ 0L:5L ]? (python-dev
topic, maybe?)
Index: Objects/abstract.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/abstract.c,v
retrieving revision 2.28
diff -C2 -r2.28 abstract.c
*** abstract.c 1999/10/12 19:54:47 2.28
--- abstract.c 2000/02/04 20:38:22
***************
*** 385,392 ****
m = tp->tp_as_sequence;
if (m && m->sq_repeat) {
! if (!PyInt_Check(w))
return type_error(
"can't multiply sequence with non-int");
! return (*m->sq_repeat)(v, (int)PyInt_AsLong(w));
}
return type_error("bad operand type(s) for *");
--- 385,403 ----
m = tp->tp_as_sequence;
if (m && m->sq_repeat) {
! long mul_value;
!
! if (PyInt_Check(w)) {
! mul_value = PyInt_AsLong(w);
! }
! else if (PyLong_Check(w)) {
! mul_value = PyLong_AsLong(w);
! if (PyErr_Occurred())
! return NULL;
! }
! else {
return type_error(
"can't multiply sequence with non-int");
! }
! return (*m->sq_repeat)(v, (int)mul_value);
}
return type_error("bad operand type(s) for *");