[3.11] gh-64490: Fix bugs in argument clinic varargs processing (GH-32092) (#100368)

(cherry picked from commit 0da728387c)
This commit is contained in:
colorfulappl 2022-12-28 09:10:06 +08:00 committed by GitHub
parent 18b43cf95f
commit a3dbd4c70e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 449 additions and 11 deletions

View file

@ -2570,7 +2570,25 @@ _PyArg_UnpackKeywordsWithVararg(PyObject *const *args, Py_ssize_t nargs,
current_arg = NULL;
}
buf[i + vararg + 1] = current_arg;
/* If an arguments is passed in as a keyword argument,
* it should be placed before `buf[vararg]`.
*
* For example:
* def f(a, /, b, *args):
* pass
* f(1, b=2)
*
* This `buf` array should be: [1, 2, NULL].
* In this case, nargs < vararg.
*
* Otherwise, we leave a place at `buf[vararg]` for vararg tuple
* so the index is `i + 1`. */
if (nargs < vararg) {
buf[i] = current_arg;
}
else {
buf[i + 1] = current_arg;
}
if (current_arg) {
--nkwargs;