summaryrefslogtreecommitdiff
path: root/Objects/intobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r--Objects/intobject.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 0202980c96..4f43b111e5 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);