diff options
author | Jeroen Demeyer <J.Demeyer@UGent.be> | 2019-06-18 08:56:53 (GMT) |
---|---|---|
committer | Inada Naoki <songofacandy@gmail.com> | 2019-06-18 08:56:53 (GMT) |
commit | 988e6aa322fb61651812fa5a61ec73316c71b041 (patch) | |
tree | 541c47762561ea2b13de9bb197c414c15513b2ec /Objects/classobject.c | |
parent | c78fe320dbb0da3412d640797eb850753d45c07b (diff) | |
download | cpython-988e6aa322fb61651812fa5a61ec73316c71b041.zip cpython-988e6aa322fb61651812fa5a61ec73316c71b041.tar.gz cpython-988e6aa322fb61651812fa5a61ec73316c71b041.tar.bz2 |
bpo-37233: use _PY_FASTCALL_SMALL_STACK in method_vectorcall (GH-13974)
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r-- | Objects/classobject.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index ec4d2b9..3062890 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -64,10 +64,16 @@ method_vectorcall(PyObject *method, PyObject *const *args, Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames); PyObject **newargs; Py_ssize_t totalargs = nargs + nkwargs; - newargs = PyMem_Malloc((totalargs+1) * sizeof(PyObject *)); - if (newargs == NULL) { - PyErr_NoMemory(); - return NULL; + PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK]; + if (totalargs <= (Py_ssize_t)Py_ARRAY_LENGTH(newargs_stack) - 1) { + newargs = newargs_stack; + } + else { + newargs = PyMem_Malloc((totalargs+1) * sizeof(PyObject *)); + if (newargs == NULL) { + PyErr_NoMemory(); + return NULL; + } } /* use borrowed references */ newargs[0] = self; @@ -77,7 +83,9 @@ method_vectorcall(PyObject *method, PyObject *const *args, memcpy(newargs + 1, args, totalargs * sizeof(PyObject *)); } result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames); - PyMem_Free(newargs); + if (newargs != newargs_stack) { + PyMem_Free(newargs); + } } return result; } |