[Python-checkins] bpo-37233: optimize method_vectorcall in case of totalargs == 0 (GH-14550)
Miss Islington (bot)
webhook-mailer at python.org
Wed Jul 3 09:06:41 EDT 2019
https://github.com/python/cpython/commit/1099e343e88ddfb46b84ba4ffc6ecc449b7f7891
commit: 1099e343e88ddfb46b84ba4ffc6ecc449b7f7891
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-07-03T06:06:38-07:00
summary:
bpo-37233: optimize method_vectorcall in case of totalargs == 0 (GH-14550)
(cherry picked from commit 53c214344038341ce86fcf7efa12dc33be9d5b45)
Co-authored-by: Jeroen Demeyer <J.Demeyer at UGent.be>
files:
M Objects/classobject.c
diff --git a/Objects/classobject.c b/Objects/classobject.c
index efdb18ef86da..12bb836cb716 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -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;
}
@@ -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);
More information about the Python-checkins
mailing list