diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-06-09 11:24:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-09 11:24:53 (GMT) |
commit | f0ff849adc6b4a01f9d1f08d9ad0f1511ff84541 (patch) | |
tree | 2297acbd995f8d481f36a923c97f77a983e5adb7 /Objects | |
parent | 570b1c971c31cd08dbf060f4e21636c40aa47786 (diff) | |
download | cpython-f0ff849adc6b4a01f9d1f08d9ad0f1511ff84541.zip cpython-f0ff849adc6b4a01f9d1f08d9ad0f1511ff84541.tar.gz cpython-f0ff849adc6b4a01f9d1f08d9ad0f1511ff84541.tar.bz2 |
bpo-30524: Fix _PyStack_UnpackDict() (#1886)
* bpo-29259: Remove unused func parameter of _PyStack_UnpackDict()
* bpo-29286: Change _PyStack_UnpackDict() prototype to be able to
notify of failure when args is NULL. _PyStack_UnpackDict() now
returns -1 on error.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/abstract.c | 19 | ||||
-rw-r--r-- | Objects/methodobject.c | 3 |
2 files changed, 11 insertions, 11 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index d838856..3585b34 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -2389,9 +2389,9 @@ _PyStack_AsDict(PyObject **values, PyObject *kwnames) return kwdict; } -PyObject ** +int _PyStack_UnpackDict(PyObject **args, Py_ssize_t nargs, PyObject *kwargs, - PyObject **p_kwnames, PyObject *func) + PyObject ***p_stack, PyObject **p_kwnames) { PyObject **stack, **kwstack; Py_ssize_t nkwargs; @@ -2402,27 +2402,27 @@ _PyStack_UnpackDict(PyObject **args, Py_ssize_t nargs, PyObject *kwargs, assert(nargs >= 0); assert(kwargs == NULL || PyDict_CheckExact(kwargs)); - nkwargs = (kwargs != NULL) ? PyDict_Size(kwargs) : 0; - if (!nkwargs) { + if (kwargs == NULL || (nkwargs = PyDict_Size(kwargs)) == 0) { + *p_stack = args; *p_kwnames = NULL; - return args; + return 0; } if ((size_t)nargs > PY_SSIZE_T_MAX / sizeof(stack[0]) - (size_t)nkwargs) { PyErr_NoMemory(); - return NULL; + return -1; } stack = PyMem_Malloc((nargs + nkwargs) * sizeof(stack[0])); if (stack == NULL) { PyErr_NoMemory(); - return NULL; + return -1; } kwnames = PyTuple_New(nkwargs); if (kwnames == NULL) { PyMem_Free(stack); - return NULL; + return -1; } /* Copy position arguments (borrowed references) */ @@ -2441,8 +2441,9 @@ _PyStack_UnpackDict(PyObject **args, Py_ssize_t nargs, PyObject *kwargs, i++; } + *p_stack = stack; *p_kwnames = kwnames; - return stack; + return 0; } PyObject * diff --git a/Objects/methodobject.c b/Objects/methodobject.c index c2001f0..fe52545 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -243,8 +243,7 @@ _PyCFunction_FastCallDict(PyObject *func_obj, PyObject **args, Py_ssize_t nargs, PyObject *kwnames; _PyCFunctionFast fastmeth = (_PyCFunctionFast)meth; - stack = _PyStack_UnpackDict(args, nargs, kwargs, &kwnames, func_obj); - if (stack == NULL) { + if (_PyStack_UnpackDict(args, nargs, kwargs, &stack, &kwnames) < 0) { return NULL; } |