summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2002-08-09 15:20:48 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2002-08-09 15:20:48 (GMT)
commit3bc3f28dbec7ec3f221d9293e05e0cf1ba5f20aa (patch)
tree81296a81fc0e196a4ca8d09ad6e1d6a5f132fd9f /Objects
parenta3502703029dbe09c705417c56191784e56a062e (diff)
downloadcpython-3bc3f28dbec7ec3f221d9293e05e0cf1ba5f20aa.zip
cpython-3bc3f28dbec7ec3f221d9293e05e0cf1ba5f20aa.tar.gz
cpython-3bc3f28dbec7ec3f221d9293e05e0cf1ba5f20aa.tar.bz2
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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/intobject.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 0202980..4f43b11 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -341,6 +341,12 @@ one that can lose catastrophic amounts of information, it's the native long
product that must have overflowed.
*/
+/* 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)
{
@@ -349,16 +355,12 @@ int_mul(PyObject *v, PyObject *w)
double doubled_longprod; /* (double)longprod */
double doubleprod; /* (double)a * (double)b */
- if (!PyInt_Check(v) &&
- v->ob_type->tp_as_sequence &&
- v->ob_type->tp_as_sequence->sq_repeat) {
+ if (USE_SQ_REPEAT(v)) {
/* 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) {
+ if (USE_SQ_REPEAT(w)) {
/* int * sequence */
a = PyInt_AsLong(v);
return (*w->ob_type->tp_as_sequence->sq_repeat)(w, a);