Commit 988e6aa3 authored by Jeroen Demeyer's avatar Jeroen Demeyer Committed by Inada Naoki

bpo-37233: use _PY_FASTCALL_SMALL_STACK in method_vectorcall (GH-13974)

parent c78fe320
......@@ -64,11 +64,17 @@ 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;
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;
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 *));
}
result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames);
if (newargs != newargs_stack) {
PyMem_Free(newargs);
}
}
return result;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment