@@ -62,9 +62,13 @@ method_vectorcall(PyObject *method, PyObject *const *args,
62
62
}
63
63
else {
64
64
Py_ssize_t nkwargs = (kwnames == NULL ) ? 0 : PyTuple_GET_SIZE (kwnames );
65
- PyObject * * newargs ;
66
65
Py_ssize_t totalargs = nargs + nkwargs ;
66
+ if (totalargs == 0 ) {
67
+ return _PyObject_Vectorcall (func , & self , 1 , NULL );
68
+ }
69
+
67
70
PyObject * newargs_stack [_PY_FASTCALL_SMALL_STACK ];
71
+ PyObject * * newargs ;
68
72
if (totalargs <= (Py_ssize_t )Py_ARRAY_LENGTH (newargs_stack ) - 1 ) {
69
73
newargs = newargs_stack ;
70
74
}
@@ -77,11 +81,11 @@ method_vectorcall(PyObject *method, PyObject *const *args,
77
81
}
78
82
/* use borrowed references */
79
83
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 * ));
85
89
result = _PyObject_Vectorcall (func , newargs , nargs + 1 , kwnames );
86
90
if (newargs != newargs_stack ) {
87
91
PyMem_Free (newargs );
0 commit comments