]> granicus.if.org Git - python/commitdiff
Make multiplying a sequence by a long integer (5L * 'b') legal
authorAndrew M. Kuchling <amk@amk.ca>
Mon, 14 Feb 2000 22:22:04 +0000 (22:22 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Mon, 14 Feb 2000 22:22:04 +0000 (22:22 +0000)
Objects/abstract.c

index c120769687dbece44d131c6cf9cc7c8b17728240..3fc312a7fe71caf774d986cc31dcfb54d79c19b2 100644 (file)
@@ -384,10 +384,21 @@ PyNumber_Multiply(v, w)
        }
        m = tp->tp_as_sequence;
        if (m && m->sq_repeat) {
-               if (!PyInt_Check(w))
+               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)PyInt_AsLong(w));
+               }
+               return (*m->sq_repeat)(v, (int)mul_value);
        }
        return type_error("bad operand type(s) for *");
 }