From: Victor Stinner Date: Mon, 16 Jan 2017 22:16:47 +0000 (+0100) Subject: Cleanup getargs.c X-Git-Tag: v3.7.0a1~1547 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=80ab22fa2c3b89efd9e1e17617d6f2ae755bbeaf;p=python Cleanup getargs.c Factorize argument checks in: * vgetargskeywordsfast() * vgetargskeywordsfast_impl() --- diff --git a/Python/getargs.c b/Python/getargs.c index 49888d11b6..4c34b2a5d3 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1453,14 +1453,6 @@ _PyArg_ParseTupleAndKeywordsFast(PyObject *args, PyObject *keywords, int retval; va_list va; - if ((args == NULL || !PyTuple_Check(args)) || - (keywords != NULL && !PyDict_Check(keywords)) || - parser == NULL) - { - PyErr_BadInternalCall(); - return 0; - } - va_start(va, parser); retval = vgetargskeywordsfast(args, keywords, parser, &va, 0); va_end(va); @@ -1474,14 +1466,6 @@ _PyArg_ParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *keywords, int retval; va_list va; - if ((args == NULL || !PyTuple_Check(args)) || - (keywords != NULL && !PyDict_Check(keywords)) || - parser == NULL) - { - PyErr_BadInternalCall(); - return 0; - } - va_start(va, parser); retval = vgetargskeywordsfast(args, keywords, parser, &va, FLAG_SIZE_T); va_end(va); @@ -1495,13 +1479,6 @@ _PyArg_ParseStack(PyObject **args, Py_ssize_t nargs, PyObject *kwnames, int retval; va_list va; - if ((kwnames != NULL && !PyTuple_Check(kwnames)) || - parser == NULL) - { - PyErr_BadInternalCall(); - return 0; - } - va_start(va, parser); retval = vgetargskeywordsfast_impl(args, nargs, NULL, kwnames, parser, &va, 0); va_end(va); @@ -1515,13 +1492,6 @@ _PyArg_ParseStack_SizeT(PyObject **args, Py_ssize_t nargs, PyObject *kwnames, int retval; va_list va; - if ((kwnames != NULL && !PyTuple_Check(kwnames)) || - parser == NULL) - { - PyErr_BadInternalCall(); - return 0; - } - va_start(va, parser); retval = vgetargskeywordsfast_impl(args, nargs, NULL, kwnames, parser, &va, FLAG_SIZE_T); va_end(va); @@ -1536,14 +1506,6 @@ _PyArg_VaParseTupleAndKeywordsFast(PyObject *args, PyObject *keywords, int retval; va_list lva; - if ((args == NULL || !PyTuple_Check(args)) || - (keywords != NULL && !PyDict_Check(keywords)) || - parser == NULL) - { - PyErr_BadInternalCall(); - return 0; - } - va_copy(lva, va); retval = vgetargskeywordsfast(args, keywords, parser, &lva, 0); @@ -1558,14 +1520,6 @@ _PyArg_VaParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *keywords, int retval; va_list lva; - if ((args == NULL || !PyTuple_Check(args)) || - (keywords != NULL && !PyDict_Check(keywords)) || - parser == NULL) - { - PyErr_BadInternalCall(); - return 0; - } - va_copy(lva, va); retval = vgetargskeywordsfast(args, keywords, parser, &lva, FLAG_SIZE_T); @@ -2010,12 +1964,20 @@ vgetargskeywordsfast_impl(PyObject **args, Py_ssize_t nargs, freelist.entries_malloced = 0; assert(keywords == NULL || PyDict_Check(keywords)); - assert(kwnames == NULL || PyTuple_Check(kwnames)); assert((keywords != NULL || kwnames != NULL) || (keywords == NULL && kwnames == NULL)); - assert(parser != NULL); assert(p_va != NULL); + if (parser == NULL) { + PyErr_BadInternalCall(); + return 0; + } + + if (kwnames != NULL && !PyTuple_Check(kwnames)) { + PyErr_BadInternalCall(); + return 0; + } + if (!parser_init(parser)) { return 0; } @@ -2204,7 +2166,13 @@ vgetargskeywordsfast(PyObject *args, PyObject *keywords, PyObject **stack; Py_ssize_t nargs; - assert(args != NULL && PyTuple_Check(args)); + if (args == NULL + || !PyTuple_Check(args) + || (keywords != NULL && !PyDict_Check(keywords))) + { + PyErr_BadInternalCall(); + return 0; + } stack = &PyTuple_GET_ITEM(args, 0); nargs = PyTuple_GET_SIZE(args);