Skip to content

bpo-37233: use _PY_FASTCALL_SMALL_STACK in method_vectorcall #13974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions Objects/classobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down