Skip to content

[3.8] bpo-37233: optimize method_vectorcall in case of totalargs == 0 (GH-14550) #14574

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
Jul 3, 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
bpo-37233: optimize method_vectorcall in case of totalargs == 0 (GH-1…
…4550)

(cherry picked from commit 53c2143)

Co-authored-by: Jeroen Demeyer <J.Demeyer@UGent.be>
  • Loading branch information
jdemeyer authored and miss-islington committed Jul 3, 2019
commit 03cf5f291abf40e322b35a0fc67fb668acc3bb1b
16 changes: 10 additions & 6 deletions Objects/classobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ method_vectorcall(PyObject *method, PyObject *const *args,
}
else {
Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
PyObject **newargs;
Py_ssize_t totalargs = nargs + nkwargs;
if (totalargs == 0) {
return _PyObject_Vectorcall(func, &self, 1, NULL);
}

PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK];
PyObject **newargs;
if (totalargs <= (Py_ssize_t)Py_ARRAY_LENGTH(newargs_stack) - 1) {
newargs = newargs_stack;
}
Expand All @@ -77,11 +81,11 @@ method_vectorcall(PyObject *method, PyObject *const *args,
}
/* use borrowed references */
newargs[0] = self;
if (totalargs) { /* bpo-37138: if totalargs == 0, then args may be
* NULL and calling memcpy() with a NULL pointer
* is undefined behaviour. */
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
}
/* bpo-37138: since totalargs > 0, it's impossible that args is NULL.
* We need this, since calling memcpy() with a NULL pointer is
* undefined behaviour. */
assert(args != NULL);
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames);
if (newargs != newargs_stack) {
PyMem_Free(newargs);
Expand Down