diff Python/ceval.c @ 12133:711340d44777 legacy-trunk

Two fixes for extended call syntax: If a non-tuple sequence is passed as the *arg, convert it to a tuple before checking its length. If named keyword arguments are used in combination with **kwargs, make a copy of kwargs before inserting the new keys.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Thu, 30 Mar 2000 23:55:31 +0000
parents e2b02d40a142
children 0ac577eb8282
line wrap: on
line diff
--- a/Python/ceval.c	Thu Mar 30 23:27:44 2000 +0000
+++ b/Python/ceval.c	Thu Mar 30 23:55:31 2000 +0000
@@ -1635,7 +1635,18 @@
 				x = NULL;
 				break;
 			    }
-			    nstar = PySequence_Length(stararg);
+			    /* Convert abstract sequence to concrete tuple */
+			    if (!PyTuple_Check(stararg)) {
+				PyObject *t = NULL;
+				t = PySequence_Tuple(stararg);
+				if (t == NULL) {
+				    x = NULL;
+				    break;
+				}
+				Py_DECREF(stararg);
+				stararg = t;
+			    }
+			    nstar = PyTuple_GET_SIZE(stararg);
 			    if (nstar < 0) {
 				x = NULL;
 				break;
@@ -1649,6 +1660,15 @@
 				    break;
 				}
 			    }
+			    else {
+				    PyObject *d = PyDict_Copy(kwdict);
+				    if (d == NULL) {
+					    x = NULL;
+					    break;
+				    }
+				    Py_DECREF(kwdict);
+				    kwdict = d;
+			    }
 			    err = 0;
 			    while (--nk >= 0) {
 				PyObject *value = POP();
@@ -1678,18 +1698,7 @@
 			    break;
 			}
 			if (stararg) {
-			    PyObject *t = NULL;
 			    int i;
-			    if (!PyTuple_Check(stararg)) {
-				/* must be sequence to pass earlier test */
-				t = PySequence_Tuple(stararg);
-				if (t == NULL) {
-				    x = NULL;
-				    break;
-				}
-				Py_DECREF(stararg);
-				stararg = t;
-			    }
 			    for (i = 0; i < nstar; i++) {
 				PyObject *a = PyTuple_GET_ITEM(stararg, i);
 				Py_INCREF(a);