From f7c2410e65e3d0d1278c22cbf457fa0ac5c205a2 Mon Sep 17 00:00:00 2001
From: Paul Sokolovsky <pfalcon@users.sourceforge.net>
Date: Sat, 8 Feb 2014 23:19:48 +0200
Subject: [PATCH] Implement tuple multiplication.

---
 py/objtuple.c              | 10 ++++++++++
 tests/basics/tuple_mult.py |  4 ++++
 2 files changed, 14 insertions(+)
 create mode 100644 tests/basics/tuple_mult.py

diff --git a/py/objtuple.c b/py/objtuple.c
index b7710e1d5..18eb6df4d 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -124,6 +124,16 @@ static mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
             m_seq_cat(s->items, o->items, o->len, p->items, p->len, mp_obj_t);
             return s;
         }
+        case RT_BINARY_OP_MULTIPLY:
+        {
+            if (!MP_OBJ_IS_SMALL_INT(rhs)) {
+                return NULL;
+            }
+            int n = MP_OBJ_SMALL_INT_VALUE(rhs);
+            mp_obj_tuple_t *s = mp_obj_new_tuple(o->len * n, NULL);
+            mp_seq_multiply(o->items, sizeof(*o->items), o->len, n, s->items);
+            return s;
+        }
         case RT_BINARY_OP_EQUAL:
         case RT_BINARY_OP_LESS:
         case RT_BINARY_OP_LESS_EQUAL:
diff --git a/tests/basics/tuple_mult.py b/tests/basics/tuple_mult.py
new file mode 100644
index 000000000..f8350f2f2
--- /dev/null
+++ b/tests/basics/tuple_mult.py
@@ -0,0 +1,4 @@
+print((0,) * 5)
+a = (1, 2, 3)
+c = a * 3
+print(c)
-- 
GitLab