cpython: a36e60c5fee0 (original) (raw)
--- a/Python/getargs.c +++ b/Python/getargs.c @@ -1545,7 +1545,7 @@ PyArg_ValidateKeywordArguments(PyObject #define IS_END_OF_FORMAT(c) (c == '\0' || c == ';' || c == ':') static int -vgetargskeywords(PyObject *args, PyObject *keywords, const char *format, +vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format, char **kwlist, va_list *p_va, int flags) { char msgbuf[512]; @@ -1555,7 +1555,7 @@ vgetargskeywords(PyObject *args, PyObjec int max = INT_MAX; int i, pos, len; int skip = 0;
- Py_ssize_t nargs, nkwargs; PyObject *current_arg; freelistentry_t static_entries[STATIC_FREELIST_ENTRIES]; freelist_t freelist; @@ -1565,7 +1565,7 @@ vgetargskeywords(PyObject *args, PyObjec freelist.entries_malloced = 0; assert(args != NULL && PyTuple_Check(args));
- assert(kwargs == NULL || PyDict_Check(kwargs)); assert(format != NULL); assert(kwlist != NULL); assert(p_va != NULL); @@ -1604,15 +1604,15 @@ vgetargskeywords(PyObject *args, PyObjec } nargs = PyTuple_GET_SIZE(args);
- nkwargs = (kwargs == NULL) ? 0 : PyDict_GET_SIZE(kwargs);
- if (nargs + nkwargs > len) { PyErr_Format(PyExc_TypeError, "%s%s takes at most %d argument%s (%zd given)", (fname == NULL) ? "function" : fname, (fname == NULL) ? "" : "()", len, (len == 1) ? "" : "s",
nargs + nkeywords);[](#l1.44)
} @@ -1673,14 +1673,14 @@ vgetargskeywords(PyObject *args, PyObjec } if (!skip) { current_arg = NULL;nargs + nkwargs);[](#l1.45) return cleanreturn(0, &freelist);[](#l1.46)
if (nkeywords && i >= pos) {[](#l1.53)
current_arg = PyDict_GetItemString(keywords, keyword);[](#l1.54)
if (nkwargs && i >= pos) {[](#l1.55)
current_arg = PyDict_GetItemString(kwargs, keyword);[](#l1.56) if (!current_arg && PyErr_Occurred()) {[](#l1.57) return cleanreturn(0, &freelist);[](#l1.58) }[](#l1.59) }[](#l1.60) if (current_arg) {[](#l1.61)
--nkeywords;[](#l1.62)
--nkwargs;[](#l1.63) if (i < nargs) {[](#l1.64) /* arg present in tuple and in dict */[](#l1.65) PyErr_Format(PyExc_TypeError,[](#l1.66)
@@ -1724,7 +1724,7 @@ vgetargskeywords(PyObject *args, PyObjec * fulfilled and no keyword args left, with no further * validation. XXX Maybe skip this in debug build ? */
if (!nkeywords && !skip) {[](#l1.71)
if (!nkwargs && !skip) {[](#l1.72) return cleanreturn(1, &freelist);[](#l1.73) }[](#l1.74) }[](#l1.75)
@@ -1756,10 +1756,10 @@ vgetargskeywords(PyObject args, PyObjec } / make sure there are no extraneous keyword arguments */
while (PyDict_Next(keywords, &pos, &key, &value)) {[](#l1.84)
while (PyDict_Next(kwargs, &pos, &key, &value)) {[](#l1.85) int match = 0;[](#l1.86) if (!PyUnicode_Check(key)) {[](#l1.87) PyErr_SetString(PyExc_TypeError,[](#l1.88)
@@ -1942,7 +1942,7 @@ find_keyword(PyObject *kwnames, PyObject static int vgetargskeywordsfast_impl(PyObject **args, Py_ssize_t nargs,
PyObject *keywords, PyObject *kwnames,[](#l1.93)
PyObject *kwargs, PyObject *kwnames,[](#l1.94) struct _PyArg_Parser *parser,[](#l1.95) va_list *p_va, int flags)[](#l1.96)
{ @@ -1953,7 +1953,7 @@ vgetargskeywordsfast_impl(PyObject **arg const char *msg; PyObject *keyword; int i, pos, len;
- Py_ssize_t nkwargs; PyObject *current_arg; freelistentry_t static_entries[STATIC_FREELIST_ENTRIES]; freelist_t freelist; @@ -1963,9 +1963,9 @@ vgetargskeywordsfast_impl(PyObject **arg freelist.first_available = 0; freelist.entries_malloced = 0;
- assert(keywords == NULL || PyDict_Check(keywords));
- assert((keywords != NULL || kwnames != NULL)
|| (keywords == NULL && kwnames == NULL));[](#l1.113)
- assert(kwargs == NULL || PyDict_Check(kwargs));
- assert((kwargs != NULL || kwnames != NULL)
assert(p_va != NULL); if (parser == NULL) { @@ -1995,24 +1995,24 @@ vgetargskeywordsfast_impl(PyObject **arg freelist.entries_malloced = 1; }|| (kwargs == NULL && kwnames == NULL));[](#l1.116)
nkeywords = PyTuple_GET_SIZE(kwnames);[](#l1.130)
nkeywords = 0;[](#l1.135)
- if (nargs + nkwargs > len) { PyErr_Format(PyExc_TypeError, "%s%s takes at most %d argument%s (%zd given)", (parser->fname == NULL) ? "function" : parser->fname, (parser->fname == NULL) ? "" : "()", len, (len == 1) ? "" : "s",
nargs + nkeywords);[](#l1.146)
} if (parser->max < nargs) { @@ -2036,9 +2036,9 @@ vgetargskeywordsfast_impl(PyObject **arg assert(!IS_END_OF_FORMAT(*format));nargs + nkwargs);[](#l1.147) return cleanreturn(0, &freelist);[](#l1.148)
if (nkeywords && i >= pos) {[](#l1.155)
if (keywords != NULL) {[](#l1.156)
current_arg = PyDict_GetItem(keywords, keyword);[](#l1.157)
if (nkwargs && i >= pos) {[](#l1.158)
if (kwargs != NULL) {[](#l1.159)
current_arg = PyDict_GetItem(kwargs, keyword);[](#l1.160) if (!current_arg && PyErr_Occurred()) {[](#l1.161) return cleanreturn(0, &freelist);[](#l1.162) }[](#l1.163)
@@ -2048,7 +2048,7 @@ vgetargskeywordsfast_impl(PyObject **arg } } if (current_arg) {
--nkeywords;[](#l1.168)
--nkwargs;[](#l1.169) if (i < nargs) {[](#l1.170) /* arg present in tuple and in dict */[](#l1.171) PyErr_Format(PyExc_TypeError,[](#l1.172)
@@ -2092,7 +2092,7 @@ vgetargskeywordsfast_impl(PyObject **arg * fulfilled and no keyword args left, with no further * validation. XXX Maybe skip this in debug build ? */
if (!nkeywords) {[](#l1.177)
if (!nkwargs) {[](#l1.178) return cleanreturn(1, &freelist);[](#l1.179) }[](#l1.180)
@@ -2105,11 +2105,11 @@ vgetargskeywordsfast_impl(PyObject **arg assert(IS_END_OF_FORMAT(*format) || (*format == '|') || (format == '$')); / make sure there are no extraneous keyword arguments */
- if (nkwargs > 0) {
if (kwargs != NULL) {[](#l1.189) PyObject *key, *value;[](#l1.190) Py_ssize_t pos = 0;[](#l1.191)
while (PyDict_Next(keywords, &pos, &key, &value)) {[](#l1.192)
while (PyDict_Next(kwargs, &pos, &key, &value)) {[](#l1.193) int match;[](#l1.194) if (!PyUnicode_Check(key)) {[](#l1.195) PyErr_SetString(PyExc_TypeError,[](#l1.196)