diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2019-06-01 17:08:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-01 17:08:04 (GMT) |
commit | cd74e66a8c420be675fd2fbf3fe708ac02ee9f21 (patch) | |
tree | 12f985512507967c339019c4c21b4a613cd6c61b /Objects | |
parent | 059b9ea5ac98f432e41b05d1fa5aab4ffa22df4d (diff) | |
download | cpython-cd74e66a8c420be675fd2fbf3fe708ac02ee9f21.zip cpython-cd74e66a8c420be675fd2fbf3fe708ac02ee9f21.tar.gz cpython-cd74e66a8c420be675fd2fbf3fe708ac02ee9f21.tar.bz2 |
bpo-37122: Make co->co_argcount represent the total number of positonal arguments in the code object (GH-13726)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/call.c | 8 | ||||
-rw-r--r-- | Objects/codeobject.c | 11 | ||||
-rw-r--r-- | Objects/typeobject.c | 2 |
3 files changed, 10 insertions, 11 deletions
diff --git a/Objects/call.c b/Objects/call.c index acd1f26..c0d1456 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -308,11 +308,11 @@ _PyFunction_FastCallDict(PyObject *func, PyObject *const *args, Py_ssize_t nargs (co->co_flags & ~PyCF_MASK) == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { /* Fast paths */ - if (argdefs == NULL && co->co_argcount + co->co_posonlyargcount == nargs) { + if (argdefs == NULL && co->co_argcount == nargs) { return function_code_fastcall(co, args, nargs, globals); } else if (nargs == 0 && argdefs != NULL - && co->co_argcount + co->co_posonlyargcount == PyTuple_GET_SIZE(argdefs)) { + && co->co_argcount == PyTuple_GET_SIZE(argdefs)) { /* function called with no arguments, but all parameters have a default value: use default values as arguments .*/ args = _PyTuple_ITEMS(argdefs); @@ -396,11 +396,11 @@ _PyFunction_Vectorcall(PyObject *func, PyObject* const* stack, if (co->co_kwonlyargcount == 0 && nkwargs == 0 && (co->co_flags & ~PyCF_MASK) == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { - if (argdefs == NULL && co->co_argcount + co->co_posonlyargcount== nargs) { + if (argdefs == NULL && co->co_argcount == nargs) { return function_code_fastcall(co, stack, nargs, globals); } else if (nargs == 0 && argdefs != NULL - && co->co_argcount + co->co_posonlyargcount == PyTuple_GET_SIZE(argdefs)) { + && co->co_argcount == PyTuple_GET_SIZE(argdefs)) { /* function called with no arguments, but all parameters have a default value: use default values as arguments .*/ stack = _PyTuple_ITEMS(argdefs); diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 886ce41..bf68e54 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -114,8 +114,9 @@ PyCode_New(int argcount, int posonlyargcount, int kwonlyargcount, Py_ssize_t i, n_cellvars, n_varnames, total_args; /* Check argument types */ - if (argcount < 0 || posonlyargcount < 0 || kwonlyargcount < 0 || - nlocals < 0 || stacksize < 0 || flags < 0 || + if (argcount < posonlyargcount || posonlyargcount < 0 || + kwonlyargcount < 0 || nlocals < 0 || + stacksize < 0 || flags < 0 || code == NULL || !PyBytes_Check(code) || consts == NULL || !PyTuple_Check(consts) || names == NULL || !PyTuple_Check(names) || @@ -152,11 +153,9 @@ PyCode_New(int argcount, int posonlyargcount, int kwonlyargcount, } n_varnames = PyTuple_GET_SIZE(varnames); - if (posonlyargcount + argcount <= n_varnames - && kwonlyargcount <= n_varnames) { + if (argcount <= n_varnames && kwonlyargcount <= n_varnames) { /* Never overflows. */ - total_args = (Py_ssize_t)posonlyargcount + (Py_ssize_t)argcount - + (Py_ssize_t)kwonlyargcount + + total_args = (Py_ssize_t)argcount + (Py_ssize_t)kwonlyargcount + ((flags & CO_VARARGS) != 0) + ((flags & CO_VARKEYWORDS) != 0); } else { diff --git a/Objects/typeobject.c b/Objects/typeobject.c index da249b5..b6d925c 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -7807,7 +7807,7 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds) "super(): no code object"); return -1; } - if (co->co_posonlyargcount + co->co_argcount == 0) { + if (co->co_argcount == 0) { PyErr_SetString(PyExc_RuntimeError, "super(): no arguments"); return -1; |