8000 bpo-37233: optimize method_vectorcall in case of totalargs == 0 (GH-1… · python/cpython@1099e34 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1099e34

Browse files
bpo-37233: optimize method_vectorcall in case of totalargs == 0 (GH-14550)
(cherry picked from commit 53c2143) Co-authored-by: Jeroen Demeyer <J.Demeyer@UGent.be>
1 parent c7570d4 commit 1099e34

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Objects/classobject.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ method_vectorcall(PyObject *method, PyObject *const *args,
6262
}
6363
else {
6464
Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
65-
PyObject **newargs;
6665
Py_ssize_t totalargs = nargs + nkwargs;
66+
if (totalargs == 0) {
67+
return _PyObject_Vectorcall(func, &self, 1, NULL);
68+
}
69+
6770
PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK];
71+
PyObject **newargs;
6872
if (totalargs <= (Py_ssize_t)Py_ARRAY_LENGTH(newargs_stack) - 1) {
6973
newargs = newargs_stack;
7074
}
@@ -77,11 +81,11 @@ method_vectorcall(PyObject *method, PyObject *const *args,
7781
}
7882
/* use borrowed references */
7983
newargs[0] = self;
80-
if (totalargs) { /* bpo-37138: if totalargs == 0, then args may be
81-
* NULL and calling memcpy() with a NULL pointer
82-
* is undefined behaviour. */
83-
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
84-
}
84+
/* bpo-37138: since totalargs > 0, it's impossible that args is NULL.
85+
* We need this, since calling memcpy() with a NULL pointer is
86+
* undefined behaviour. */
87+
assert(args != NULL);
88+
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
8589
result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames);
8690
if (newargs != newargs_stack) {
8791
PyMem_Free(newargs);

0 commit comments

Comments
 (0)
0