mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.8] bpo-37233: use _PY_FASTCALL_SMALL_STACK in method_vectorcall (GH-13974)
(cherry picked from commit 988e6aa322
)
Co-authored-by: Jeroen Demeyer <J.Demeyer@UGent.be>
This commit is contained in:
parent
0aefba7f99
commit
c7570d402e
1 changed files with 13 additions and 5 deletions
|
@ -64,11 +64,17 @@ method_vectorcall(PyObject *method, PyObject *const *args,
|
||||||
Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
|
Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
|
||||||
PyObject **newargs;
|
PyObject **newargs;
|
||||||
Py_ssize_t totalargs = nargs + nkwargs;
|
Py_ssize_t totalargs = nargs + nkwargs;
|
||||||
|
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 *));
|
newargs = PyMem_Malloc((totalargs+1) * sizeof(PyObject *));
|
||||||
if (newargs == NULL) {
|
if (newargs == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* use borrowed references */
|
/* use borrowed references */
|
||||||
newargs[0] = self;
|
newargs[0] = self;
|
||||||
if (totalargs) { /* bpo-37138: if totalargs == 0, then args may be
|
if (totalargs) { /* bpo-37138: if totalargs == 0, then args may be
|
||||||
|
@ -77,8 +83,10 @@ method_vectorcall(PyObject *method, PyObject *const *args,
|
||||||
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
|
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
|
||||||
}
|
}
|
||||||
result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames);
|
result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames);
|
||||||
|
if (newargs != newargs_stack) {
|
||||||
PyMem_Free(newargs);
|
PyMem_Free(newargs);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue