cpython: 288ec55f1912 (original) (raw)

--- a/Python/ceval.c +++ b/Python/ceval.c @@ -3793,12 +3793,13 @@ static PyObject * PyFrameObject *f; PyObject *retval = NULL; PyObject **fastlocals, **freevars;

+

if (globals == NULL) { PyErr_SetString(PyExc_SystemError, @@ -3806,36 +3807,50 @@ static PyObject * return NULL; }

-

+

@@ -3843,17 +3858,21 @@ static PyObject * PyTuple_SET_ITEM(u, i-n, x); } } +

+ if (keyword == NULL || !PyUnicode_Check(keyword)) { PyErr_Format(PyExc_TypeError, "%U() keywords must be strings", co->co_name); goto fail; } + /* Speed hack: do raw pointer compares. As names are normally interned this should almost always hit. */ co_varnames = ((PyTupleObject *)(co->co_varnames))->ob_item; @@ -3862,6 +3881,7 @@ static PyObject if (nm == keyword) goto kw_found; } + / Slow fallback, just in case */ for (j = 0; j < total_args; j++) { PyObject *nm = co_varnames[j]; @@ -3872,6 +3892,7 @@ static PyObject * else if (cmp < 0) goto fail; } + if (j >= total_args && kwdict == NULL) { PyErr_Format(PyExc_TypeError, "%U() got an unexpected " @@ -3880,10 +3901,12 @@ static PyObject * keyword); goto fail; } + if (PyDict_SetItem(kwdict, keyword, value) == -1) { goto fail; } continue; + kw_found: if (GETLOCAL(j) != NULL) { PyErr_Format(PyExc_TypeError, @@ -3896,10 +3919,14 @@ static PyObject * Py_INCREF(value); SETLOCAL(j, value); } +

@@ -3922,6 +3949,8 @@ static PyObject * } } } +

@@ -3964,12 +3993,15 @@ static PyObject * goto fail; SETLOCAL(co->co_nlocals + i, c); } +