mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Issue #18896: Python function can now have more than 255 parameters.
collections.namedtuple() now supports tuples with more than 255 elements.
This commit is contained in:
parent
14d8b9693b
commit
5bb8b9134b
10 changed files with 33 additions and 49 deletions
|
@ -110,7 +110,7 @@ PyCode_New(int argcount, int kwonlyargcount,
|
|||
PyObject *lnotab)
|
||||
{
|
||||
PyCodeObject *co;
|
||||
unsigned char *cell2arg = NULL;
|
||||
Py_ssize_t *cell2arg = NULL;
|
||||
Py_ssize_t i, n_cellvars;
|
||||
|
||||
/* Check argument types */
|
||||
|
@ -142,19 +142,25 @@ PyCode_New(int argcount, int kwonlyargcount,
|
|||
if (n_cellvars) {
|
||||
Py_ssize_t total_args = argcount + kwonlyargcount +
|
||||
((flags & CO_VARARGS) != 0) + ((flags & CO_VARKEYWORDS) != 0);
|
||||
Py_ssize_t alloc_size = sizeof(unsigned char) * n_cellvars;
|
||||
bool used_cell2arg = false;
|
||||
cell2arg = PyMem_MALLOC(alloc_size);
|
||||
if (cell2arg == NULL)
|
||||
cell2arg = PyMem_NEW(Py_ssize_t, n_cellvars);
|
||||
if (cell2arg == NULL) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
memset(cell2arg, CO_CELL_NOT_AN_ARG, alloc_size);
|
||||
}
|
||||
/* Find cells which are also arguments. */
|
||||
for (i = 0; i < n_cellvars; i++) {
|
||||
Py_ssize_t j;
|
||||
PyObject *cell = PyTuple_GET_ITEM(cellvars, i);
|
||||
cell2arg[i] = CO_CELL_NOT_AN_ARG;
|
||||
for (j = 0; j < total_args; j++) {
|
||||
PyObject *arg = PyTuple_GET_ITEM(varnames, j);
|
||||
if (!PyUnicode_Compare(cell, arg)) {
|
||||
int cmp = PyUnicode_Compare(cell, arg);
|
||||
if (cmp == -1 && PyErr_Occurred()) {
|
||||
PyMem_FREE(cell2arg);
|
||||
return NULL;
|
||||
}
|
||||
if (cmp == 0) {
|
||||
cell2arg[i] = j;
|
||||
used_cell2arg = true;
|
||||
break;
|
||||
|
@ -449,7 +455,7 @@ code_sizeof(PyCodeObject *co, void *unused)
|
|||
|
||||
res = _PyObject_SIZE(Py_TYPE(co));
|
||||
if (co->co_cell2arg != NULL && co->co_cellvars != NULL)
|
||||
res += PyTuple_GET_SIZE(co->co_cellvars) * sizeof(unsigned char);
|
||||
res += PyTuple_GET_SIZE(co->co_cellvars) * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSsize_t(res);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue