]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added UNPACK_VARARG code.
authorGuido van Rossum <guido@python.org>
Tue, 14 Jan 1992 18:29:20 +0000 (18:29 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 14 Jan 1992 18:29:20 +0000 (18:29 +0000)
Python/ceval.c

index 129d74315a107a8d6327eb1164fc4d2695676540..cc2f034b798c93be11d7e8ed361a318a44009e64 100644 (file)
@@ -639,6 +639,42 @@ eval_code(co, globals, locals, arg)
                                err_setstr(NameError, getstringvalue(w));
                        break;
                
+               case UNPACK_VARARG:
+                       if (EMPTY()) {
+                               err_setstr(TypeError,
+                                          "no argument list");
+                               why = WHY_EXCEPTION;
+                               break;
+                       }
+                       v = POP();
+                       if (!is_tupleobject(v)) {
+                               err_setstr(TypeError,
+                                          "bad argument list");
+                               why = WHY_EXCEPTION;
+                       }
+                       else if (gettuplesize(v) < oparg) {
+                               err_setstr(TypeError,
+                                       "not enough arguments");
+                               why = WHY_EXCEPTION;
+                       }
+                       else if (oparg == 0) {
+                               PUSH(v);
+                               break;
+                       }
+                       else {
+                               x = gettupleslice(v, oparg, gettuplesize(v));
+                               if (x != NULL) {
+                                       PUSH(x);
+                                       for (; --oparg >= 0; ) {
+                                               w = gettupleitem(v, oparg);
+                                               INCREF(w);
+                                               PUSH(w);
+                                       }
+                               }
+                       }
+                       DECREF(v);
+                       break;
+               
                case UNPACK_ARG:
                        /* Implement various compatibility hacks:
                           (a) f(a,b,...) should accept f((1,2,...))