summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2019-06-01 17:08:04 (GMT)
committerGitHub <noreply@github.com>2019-06-01 17:08:04 (GMT)
commitcd74e66a8c420be675fd2fbf3fe708ac02ee9f21 (patch)
tree12f985512507967c339019c4c21b4a613cd6c61b /Python
parent059b9ea5ac98f432e41b05d1fa5aab4ffa22df4d (diff)
downloadcpython-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 'Python')
-rw-r--r--Python/ceval.c46
-rw-r--r--Python/compile.c8
2 files changed, 19 insertions, 35 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index f9ff4e0..d9a71e9 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3757,10 +3757,10 @@ missing_arguments(PyThreadState *tstate, PyCodeObject *co,
return;
if (positional) {
start = 0;
- end = co->co_posonlyargcount + co->co_argcount - defcount;
+ end = co->co_argcount - defcount;
}
else {
- start = co->co_posonlyargcount + co->co_argcount;
+ start = co->co_argcount;
end = start + co->co_kwonlyargcount;
}
for (i = start; i < end; i++) {
@@ -3788,25 +3788,23 @@ too_many_positional(PyThreadState *tstate, PyCodeObject *co,
Py_ssize_t kwonly_given = 0;
Py_ssize_t i;
PyObject *sig, *kwonly_sig;
- Py_ssize_t co_posonlyargcount = co->co_posonlyargcount;
Py_ssize_t co_argcount = co->co_argcount;
- Py_ssize_t total_positional = co_argcount + co_posonlyargcount;
assert((co->co_flags & CO_VARARGS) == 0);
/* Count missing keyword-only args. */
- for (i = total_positional; i < total_positional + co->co_kwonlyargcount; i++) {
+ for (i = co_argcount; i < co_argcount + co->co_kwonlyargcount; i++) {
if (GETLOCAL(i) != NULL) {
kwonly_given++;
}
}
if (defcount) {
- Py_ssize_t atleast = total_positional - defcount;
+ Py_ssize_t atleast = co_argcount - defcount;
plural = 1;
- sig = PyUnicode_FromFormat("from %zd to %zd", atleast, total_positional);
+ sig = PyUnicode_FromFormat("from %zd to %zd", atleast, co_argcount);
}
else {
- plural = (total_positional != 1);
- sig = PyUnicode_FromFormat("%zd", total_positional);
+ plural = (co_argcount != 1);
+ sig = PyUnicode_FromFormat("%zd", co_argcount);
}
if (sig == NULL)
return;
@@ -3917,7 +3915,7 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
PyObject *retval = NULL;
PyObject **fastlocals, **freevars;
PyObject *x, *u;
- const Py_ssize_t total_args = co->co_argcount + co->co_kwonlyargcount + co->co_posonlyargcount;
+ const Py_ssize_t total_args = co->co_argcount + co->co_kwonlyargcount;
Py_ssize_t i, j, n;
PyObject *kwdict;
@@ -3953,9 +3951,9 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
kwdict = NULL;
}
- /* Copy positional only arguments into local variables */
- if (argcount > co->co_argcount + co->co_posonlyargcount) {
- n = co->co_posonlyargcount;
+ /* Copy all positional arguments into local variables */
+ if (argcount > co->co_argcount) {
+ n = co->co_argcount;
}
else {
n = argcount;
@@ -3966,20 +3964,6 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
SETLOCAL(j, x);
}
-
- /* Copy positional arguments into local variables */
- if (argcount > co->co_argcount + co->co_posonlyargcount) {
- n += co->co_argcount;
- }
- else {
- n = argcount;
- }
- for (i = j; i < n; i++) {
- x = args[i];
- Py_INCREF(x);
- SETLOCAL(i, x);
- }
-
/* Pack other positional arguments into the *args argument */
if (co->co_flags & CO_VARARGS) {
u = _PyTuple_FromArray(args + n, argcount - n);
@@ -4059,14 +4043,14 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
}
/* Check the number of positional arguments */
- if ((argcount > co->co_argcount + co->co_posonlyargcount) && !(co->co_flags & CO_VARARGS)) {
+ if ((argcount > co->co_argcount) && !(co->co_flags & CO_VARARGS)) {
too_many_positional(tstate, co, argcount, defcount, fastlocals);
goto fail;
}
/* Add missing positional arguments (copy default values from defs) */
- if (argcount < co->co_posonlyargcount + co->co_argcount) {
- Py_ssize_t m = co->co_posonlyargcount + co->co_argcount - defcount;
+ if (argcount < co->co_argcount) {
+ Py_ssize_t m = co->co_argcount - defcount;
Py_ssize_t missing = 0;
for (i = argcount; i < m; i++) {
if (GETLOCAL(i) == NULL) {
@@ -4093,7 +4077,7 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
/* Add missing keyword arguments (copy default values from kwdefs) */
if (co->co_kwonlyargcount > 0) {
Py_ssize_t missing = 0;
- for (i = co->co_posonlyargcount + co->co_argcount; i < total_args; i++) {
+ for (i = co->co_argcount; i < total_args; i++) {
PyObject *name;
if (GETLOCAL(i) != NULL)
continue;
diff --git a/Python/compile.c b/Python/compile.c
index f6ec929..9e4a209 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -5764,7 +5764,7 @@ makecode(struct compiler *c, struct assembler *a)
Py_ssize_t nlocals;
int nlocals_int;
int flags;
- int argcount, posonlyargcount, kwonlyargcount, maxdepth;
+ int posorkeywordargcount, posonlyargcount, kwonlyargcount, maxdepth;
consts = consts_dict_keys_inorder(c->u->u_consts);
names = dict_keys_inorder(c->u->u_names, 0);
@@ -5808,15 +5808,15 @@ makecode(struct compiler *c, struct assembler *a)
goto error;
}
- argcount = Py_SAFE_DOWNCAST(c->u->u_argcount, Py_ssize_t, int);
posonlyargcount = Py_SAFE_DOWNCAST(c->u->u_posonlyargcount, Py_ssize_t, int);
+ posorkeywordargcount = Py_SAFE_DOWNCAST(c->u->u_argcount, Py_ssize_t, int);
kwonlyargcount = Py_SAFE_DOWNCAST(c->u->u_kwonlyargcount, Py_ssize_t, int);
maxdepth = stackdepth(c);
if (maxdepth < 0) {
goto error;
}
- co = PyCode_New(argcount, posonlyargcount, kwonlyargcount,
- nlocals_int, maxdepth, flags,
+ co = PyCode_New(posonlyargcount+posorkeywordargcount, posonlyargcount,
+ kwonlyargcount, nlocals_int, maxdepth, flags,
bytecode, consts, names, varnames,
freevars, cellvars,
c->c_filename, c->u->u_name,