summaryrefslogtreecommitdiff
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-09-15 03:14:32 +0000
committerGuido van Rossum <guido@python.org>2001-09-15 03:14:32 +0000
commit7e35d57c0cd94b136d613129cb22a2b4252aa008 (patch)
tree04cbba26e20c258dff63ab627b21906641d5c58a /Objects/longobject.c
parent0891ac017dd02f9c592c40940dff6b050523be00 (diff)
downloadcpython-git-7e35d57c0cd94b136d613129cb22a2b4252aa008.tar.gz
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!
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 7c4f75dc6e..1e01bf074b 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -183,6 +183,8 @@ PyLong_AsLong(PyObject *vv)
int i, sign;
if (vv == NULL || !PyLong_Check(vv)) {
+ if (vv != NULL && PyInt_Check(vv))
+ return PyInt_AsLong(vv);
PyErr_BadInternalCall();
return -1;
}
@@ -1448,17 +1450,19 @@ long_mul(PyLongObject *v, PyLongObject *w)
int size_a;
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);
+ 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);
size_b = ABS(b->ob_size);