diff options
author | Jeroen Demeyer <J.Demeyer@UGent.be> | 2019-07-03 10:54:00 (GMT) |
---|---|---|
committer | Inada Naoki <songofacandy@gmail.com> | 2019-07-03 10:53:59 (GMT) |
commit | 53c214344038341ce86fcf7efa12dc33be9d5b45 (patch) | |
tree | b7526d4cb5e006169213c1edb7f0688981f68cb5 /Objects | |
parent | 469d1a70cecc918499c288fc0e5e3d79711bc5e5 (diff) | |
download | cpython-53c214344038341ce86fcf7efa12dc33be9d5b45.zip cpython-53c214344038341ce86fcf7efa12dc33be9d5b45.tar.gz cpython-53c214344038341ce86fcf7efa12dc33be9d5b45.tar.bz2 |
bpo-37233: optimize method_vectorcall in case of totalargs == 0 (GH-14550)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/classobject.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index 3062890..46525a7 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); |