summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-12-16 17:19:02 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-12-16 17:19:02 (GMT)
commit5bb8b9134b0bb35a73c76657f41cafa3e4361fcd (patch)
tree5755343717913be71dc48d94db681d1a21ff31d2 /Objects
parent14d8b9693be235240ab2dcac3b43a4a7c30483bc (diff)
downloadcpython-5bb8b9134b0bb35a73c76657f41cafa3e4361fcd.zip
cpython-5bb8b9134b0bb35a73c76657f41cafa3e4361fcd.tar.gz
cpython-5bb8b9134b0bb35a73c76657f41cafa3e4361fcd.tar.bz2
Issue #18896: Python function can now have more than 255 parameters.
collections.namedtuple() now supports tuples with more than 255 elements.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/codeobject.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 788818d..0857554 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -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);
}