From ba86008aac6890c5c4a2c6d30ea8110f228d483e Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 20 Nov 2016 12:16:46 +0200 Subject: Issue #19569: Compiler warnings are now emitted if use most of deprecated functions. --- Objects/codeobject.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Objects/codeobject.c') diff --git a/Objects/codeobject.c b/Objects/codeobject.c index f7f91a8168..788818d303 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -115,7 +115,7 @@ PyCode_New(int argcount, int kwonlyargcount, /* Check argument types */ if (argcount < 0 || kwonlyargcount < 0 || nlocals < 0 || - code == NULL || + code == NULL || !PyBytes_Check(code) || consts == NULL || !PyTuple_Check(consts) || names == NULL || !PyTuple_Check(names) || varnames == NULL || !PyTuple_Check(varnames) || @@ -123,8 +123,7 @@ PyCode_New(int argcount, int kwonlyargcount, cellvars == NULL || !PyTuple_Check(cellvars) || name == NULL || !PyUnicode_Check(name) || filename == NULL || !PyUnicode_Check(filename) || - lnotab == NULL || !PyBytes_Check(lnotab) || - !PyObject_CheckReadBuffer(code)) { + lnotab == NULL || !PyBytes_Check(lnotab)) { PyErr_BadInternalCall(); return NULL; } -- cgit v1.2.1 From b738df1cd4bcfdf6e01ea459ca559cd64f0bf6f3 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 16 Dec 2016 19:19:02 +0200 Subject: Issue #18896: Python function can now have more than 255 parameters. collections.namedtuple() now supports tuples with more than 255 elements. --- Objects/codeobject.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'Objects/codeobject.c') diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 788818d303..0857554adc 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); } -- cgit v1.2.1