diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-02-25 15:59:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-25 15:59:46 (GMT) |
commit | a24107b04c1277e3c1105f98aff5bfa3a98b33a0 (patch) | |
tree | 55aa5a700e08e3ba27b0361df2b1043be5c4701a /Python/getargs.c | |
parent | a180b007d96fe68b32f11dec720fbd0cd5b6758a (diff) | |
download | cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.zip cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.gz cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.bz2 |
bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)
Diffstat (limited to 'Python/getargs.c')
-rw-r--r-- | Python/getargs.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index 0e07555..ba1a9d4 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1763,9 +1763,13 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format, current_arg = PyTuple_GET_ITEM(args, i); } else if (nkwargs && i >= pos) { - current_arg = PyDict_GetItemString(kwargs, kwlist[i]); - if (current_arg) + current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]); + if (current_arg) { --nkwargs; + } + else if (PyErr_Occurred()) { + return cleanreturn(0, &freelist); + } } else { current_arg = NULL; @@ -1844,7 +1848,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format, Py_ssize_t j; /* make sure there are no arguments given by name and position */ for (i = pos; i < nargs; i++) { - current_arg = PyDict_GetItemString(kwargs, kwlist[i]); + current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]); if (current_arg) { /* arg present in tuple and in dict */ PyErr_Format(PyExc_TypeError, @@ -1855,6 +1859,9 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format, kwlist[i], i+1); return cleanreturn(0, &freelist); } + else if (PyErr_Occurred()) { + return cleanreturn(0, &freelist); + } } /* make sure there are no extraneous keyword arguments */ j = 0; @@ -2016,13 +2023,10 @@ parser_clear(struct _PyArg_Parser *parser) } static PyObject* -find_keyword(PyObject *kwargs, PyObject *kwnames, PyObject *const *kwstack, PyObject *key) +find_keyword(PyObject *kwnames, PyObject *const *kwstack, PyObject *key) { Py_ssize_t i, nkwargs; - if (kwargs != NULL) { - return PyDict_GetItem(kwargs, key); - } nkwargs = PyTuple_GET_SIZE(kwnames); for (i=0; i < nkwargs; i++) { PyObject *kwname = PyTuple_GET_ITEM(kwnames, i); @@ -2157,9 +2161,18 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs, } else if (nkwargs && i >= pos) { keyword = PyTuple_GET_ITEM(kwtuple, i - pos); - current_arg = find_keyword(kwargs, kwnames, kwstack, keyword); - if (current_arg) + if (kwargs != NULL) { + current_arg = PyDict_GetItemWithError(kwargs, keyword); + if (!current_arg && PyErr_Occurred()) { + return cleanreturn(0, &freelist); + } + } + else { + current_arg = find_keyword(kwnames, kwstack, keyword); + } + if (current_arg) { --nkwargs; + } } else { current_arg = NULL; @@ -2220,7 +2233,15 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs, /* make sure there are no arguments given by name and position */ for (i = pos; i < nargs; i++) { keyword = PyTuple_GET_ITEM(kwtuple, i - pos); - current_arg = find_keyword(kwargs, kwnames, kwstack, keyword); + if (kwargs != NULL) { + current_arg = PyDict_GetItemWithError(kwargs, keyword); + if (!current_arg && PyErr_Occurred()) { + return cleanreturn(0, &freelist); + } + } + else { + current_arg = find_keyword(kwnames, kwstack, keyword); + } if (current_arg) { /* arg present in tuple and in dict */ PyErr_Format(PyExc_TypeError, |