[Python-checkins] (no subject)

Łukasz Langa webhook-mailer at python.org
Tue Jul 23 06:39:56 EDT 2019




To: python-checkins at python.org
Subject: [3.8] bpo-36974: separate vectorcall functions for each calling
 convention (GH-13781) (#14782)
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

https://github.com/python/cpython/commit/bf8e82f976b37856c7d35cdf88a238cb6f57=
fe65
commit: bf8e82f976b37856c7d35cdf88a238cb6f57fe65
branch: 3.8
author: Jeroen Demeyer <J.Demeyer at UGent.be>
committer: =C5=81ukasz Langa <lukasz at langa.pl>
date: 2019-07-23T12:39:51+02:00
summary:

[3.8] bpo-36974: separate vectorcall functions for each calling convention (G=
H-13781) (#14782)

files:
A Misc/NEWS.d/next/Core and Builtins/2019-06-11-12-59-38.bpo-36974.bVYmSA.rst
M Include/descrobject.h
M Include/methodobject.h
M Lib/test/test_call.py
M Lib/test/test_gdb.py
M Objects/call.c
M Objects/descrobject.c
M Objects/methodobject.c
M Python/ceval.c
M Tools/gdb/libpython.py

diff --git a/Include/descrobject.h b/Include/descrobject.h
index d7114852c1e2..ead269d1d2f7 100644
--- a/Include/descrobject.h
+++ b/Include/descrobject.h
@@ -91,9 +91,6 @@ PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *,
 PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
                                                struct PyGetSetDef *);
 #ifndef Py_LIMITED_API
-
-PyAPI_FUNC(PyObject *) _PyMethodDescr_Vectorcall(
-        PyObject *descrobj, PyObject *const *args, size_t nargsf, PyObject *=
kwnames);
 PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
                                                 struct wrapperbase *, void *=
);
 #define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set !=3D NULL)
diff --git a/Include/methodobject.h b/Include/methodobject.h
index e92adde7bf6b..ba3b8878a6c4 100644
--- a/Include/methodobject.h
+++ b/Include/methodobject.h
@@ -46,11 +46,6 @@ PyAPI_FUNC(PyObject *) _PyCFunction_FastCallDict(PyObject =
*func,
     PyObject *const *args,
     Py_ssize_t nargs,
     PyObject *kwargs);
-
-PyAPI_FUNC(PyObject *) _PyCFunction_Vectorcall(PyObject *func,
-    PyObject *const *stack,
-    size_t nargsf,
-    PyObject *kwnames);
 #endif
=20
 struct PyMethodDef {
diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py
index b252ca1076ad..0bff7ded4670 100644
--- a/Lib/test/test_call.py
+++ b/Lib/test/test_call.py
@@ -586,6 +586,8 @@ def __call__(self, *args):
                 return super().__call__(*args)
=20
         calls +=3D [
+            (dict.update, ({},), {"key":True}, None),
+            ({}.update, ({},), {"key":True}, None),
             (MethodDescriptorHeap(), (0,), {}, True),
             (MethodDescriptorOverridden(), (0,), {}, 'new'),
             (MethodDescriptorSuper(), (0,), {}, True),
diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py
index 1c5e18b678ca..e07d3273a455 100644
--- a/Lib/test/test_gdb.py
+++ b/Lib/test/test_gdb.py
@@ -850,10 +850,10 @@ def test_pycfunction(self):
         # called, so test a variety of calling conventions.
         for py_name, py_args, c_name, expected_frame_number in (
             ('gmtime', '', 'time_gmtime', 1),  # METH_VARARGS
-            ('len', '[]', 'builtin_len', 2),  # METH_O
-            ('locals', '', 'builtin_locals', 2),  # METH_NOARGS
-            ('iter', '[]', 'builtin_iter', 2),  # METH_FASTCALL
-            ('sorted', '[]', 'builtin_sorted', 2),  # METH_FASTCALL|METH_KEY=
WORDS
+            ('len', '[]', 'builtin_len', 1),  # METH_O
+            ('locals', '', 'builtin_locals', 1),  # METH_NOARGS
+            ('iter', '[]', 'builtin_iter', 1),  # METH_FASTCALL
+            ('sorted', '[]', 'builtin_sorted', 1),  # METH_FASTCALL|METH_KEY=
WORDS
         ):
             with self.subTest(c_name):
                 cmd =3D ('from time import gmtime\n'  # (not always needed)
diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-06-11-12-59-38.bpo-36974=
.bVYmSA.rst b/Misc/NEWS.d/next/Core and Builtins/2019-06-11-12-59-38.bpo-3697=
4.bVYmSA.rst
new file mode 100644
index 000000000000..6080ef361814
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2019-06-11-12-59-38.bpo-36974.bVYmSA=
.rst=09
@@ -0,0 +1,2 @@
+Implemented separate vectorcall functions for every calling convention of
+builtin functions and methods. This improves performance for calls.
diff --git a/Objects/call.c b/Objects/call.c
index 1f41f5cb6bbf..c66389854d8b 100644
--- a/Objects/call.c
+++ b/Objects/call.c
@@ -206,7 +206,7 @@ PyVectorcall_Call(PyObject *callable, PyObject *tuple, Py=
Object *kwargs)
         Py_DECREF(kwnames);
     }
=20
-    return result;
+    return _Py_CheckFunctionResult(callable, result, NULL);
 }
=20
=20
@@ -723,25 +723,6 @@ _PyMethodDef_RawFastCallKeywords(PyMethodDef *method, Py=
Object *self,
 }
=20
=20
-PyObject *
-_PyCFunction_Vectorcall(PyObject *func,
-                        PyObject *const *args, size_t nargsf,
-                        PyObject *kwnames)
-{
-    PyObject *result;
-
-    assert(func !=3D NULL);
-    assert(PyCFunction_Check(func));
-    Py_ssize_t nargs =3D PyVectorcall_NARGS(nargsf);
-
-    result =3D _PyMethodDef_RawFastCallKeywords(((PyCFunctionObject*)func)->=
m_ml,
-                                              PyCFunction_GET_SELF(func),
-                                              args, nargs, kwnames);
-    result =3D _Py_CheckFunctionResult(func, result, NULL);
-    return result;
-}
-
-
 static PyObject *
 cfunction_call_varargs(PyObject *func, PyObject *args, PyObject *kwargs)
 {
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 6c95a8726c42..dbb44de846fd 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -226,80 +226,199 @@ getset_set(PyGetSetDescrObject *descr, PyObject *obj, =
PyObject *value)
     return -1;
 }
=20
-static PyObject *
-methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwarg=
s)
-{
-    Py_ssize_t nargs;
-    PyObject *self, *result;
=20
-    /* Make sure that the first argument is acceptable as 'self' */
-    assert(PyTuple_Check(args));
-    nargs =3D PyTuple_GET_SIZE(args);
+/* Vectorcall functions for each of the PyMethodDescr calling conventions.
+ *
+ * First, common helpers
+ */
+static const char *
+get_name(PyObject *func) {
+    assert(PyObject_TypeCheck(func, &PyMethodDescr_Type));
+    return ((PyMethodDescrObject *)func)->d_method->ml_name;
+}
+
+typedef void (*funcptr)(void);
+
+static inline int
+method_check_args(PyObject *func, PyObject *const *args, Py_ssize_t nargs, P=
yObject *kwnames)
+{
+    assert(!PyErr_Occurred());
+    assert(PyObject_TypeCheck(func, &PyMethodDescr_Type));
     if (nargs < 1) {
         PyErr_Format(PyExc_TypeError,
-                     "descriptor '%V' of '%.100s' "
+                     "descriptor '%.200s' of '%.100s' "
                      "object needs an argument",
-                     descr_name((PyDescrObject *)descr), "?",
-                     PyDescr_TYPE(descr)->tp_name);
-        return NULL;
+                     get_name(func), PyDescr_TYPE(func)->tp_name);
+        return -1;
     }
-    self =3D PyTuple_GET_ITEM(args, 0);
+    PyObject *self =3D args[0];
     if (!_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
-                                  (PyObject *)PyDescr_TYPE(descr))) {
+                                  (PyObject *)PyDescr_TYPE(func)))
+    {
         PyErr_Format(PyExc_TypeError,
-                     "descriptor '%V' for '%.100s' objects "
+                     "descriptor '%.200s' for '%.100s' objects "
                      "doesn't apply to a '%.100s' object",
-                     descr_name((PyDescrObject *)descr), "?",
-                     PyDescr_TYPE(descr)->tp_name,
-                     self->ob_type->tp_name);
+                     get_name(func), PyDescr_TYPE(func)->tp_name,
+                     Py_TYPE(self)->tp_name);
+        return -1;
+    }
+    if (kwnames && PyTuple_GET_SIZE(kwnames)) {
+        PyErr_Format(PyExc_TypeError,
+                     "%.200s() takes no keyword arguments", get_name(func));
+        return -1;
+    }
+    return 0;
+}
+
+static inline funcptr
+method_enter_call(PyObject *func)
+{
+    if (Py_EnterRecursiveCall(" while calling a Python object")) {
         return NULL;
     }
+    return (funcptr)((PyMethodDescrObject *)func)->d_method->ml_meth;
+}
=20
-    result =3D _PyMethodDef_RawFastCallDict(descr->d_method, self,
-                                          &_PyTuple_ITEMS(args)[1], nargs - =
1,
-                                          kwargs);
-    result =3D _Py_CheckFunctionResult((PyObject *)descr, result, NULL);
+/* Now the actual vectorcall functions */
+static PyObject *
+method_vectorcall_VARARGS(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
+{
+    Py_ssize_t nargs =3D PyVectorcall_NARGS(nargsf);
+    if (method_check_args(func, args, nargs, kwnames)) {
+        return NULL;
+    }
+    PyObject *argstuple =3D _PyTuple_FromArray(args+1, nargs-1);
+    if (argstuple =3D=3D NULL) {
+        return NULL;
+    }
+    PyCFunction meth =3D (PyCFunction)method_enter_call(func);
+    if (meth =3D=3D NULL) {
+        Py_DECREF(argstuple);
+        return NULL;
+    }
+    PyObject *result =3D meth(args[0], argstuple);
+    Py_DECREF(argstuple);
+    Py_LeaveRecursiveCall();
     return result;
 }
=20
-// same to methoddescr_call(), but use FASTCALL convention.
-PyObject *
-_PyMethodDescr_Vectorcall(PyObject *descrobj,
-                          PyObject *const *args, size_t nargsf,
-                          PyObject *kwnames)
+static PyObject *
+method_vectorcall_VARARGS_KEYWORDS(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
 {
-    assert(Py_TYPE(descrobj) =3D=3D &PyMethodDescr_Type);
-    PyMethodDescrObject *descr =3D (PyMethodDescrObject *)descrobj;
-    PyObject *self, *result;
+    Py_ssize_t nargs =3D PyVectorcall_NARGS(nargsf);
+    if (method_check_args(func, args, nargs, NULL)) {
+        return NULL;
+    }
+    PyObject *argstuple =3D _PyTuple_FromArray(args+1, nargs-1);
+    if (argstuple =3D=3D NULL) {
+        return NULL;
+    }
+    PyObject *result =3D NULL;
+    /* Create a temporary dict for keyword arguments */
+    PyObject *kwdict =3D NULL;
+    if (kwnames !=3D NULL && PyTuple_GET_SIZE(kwnames) > 0) {
+        kwdict =3D _PyStack_AsDict(args + nargs, kwnames);
+        if (kwdict =3D=3D NULL) {
+            goto exit;
+        }
+    }
+    PyCFunctionWithKeywords meth =3D (PyCFunctionWithKeywords)
+                                   method_enter_call(func);
+    if (meth =3D=3D NULL) {
+        goto exit;
+    }
+    result =3D meth(args[0], argstuple, kwdict);
+    Py_LeaveRecursiveCall();
+exit:
+    Py_DECREF(argstuple);
+    Py_XDECREF(kwdict);
+    return result;
+}
=20
+static PyObject *
+method_vectorcall_FASTCALL(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
+{
     Py_ssize_t nargs =3D PyVectorcall_NARGS(nargsf);
-    /* Make sure that the first argument is acceptable as 'self' */
-    if (nargs < 1) {
-        PyErr_Format(PyExc_TypeError,
-                     "descriptor '%V' of '%.100s' "
-                     "object needs an argument",
-                     descr_name((PyDescrObject *)descr), "?",
-                     PyDescr_TYPE(descr)->tp_name);
+    if (method_check_args(func, args, nargs, kwnames)) {
         return NULL;
     }
-    self =3D args[0];
-    if (!_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
-                                  (PyObject *)PyDescr_TYPE(descr))) {
+    _PyCFunctionFast meth =3D (_PyCFunctionFast)
+                            method_enter_call(func);
+    if (meth =3D=3D NULL) {
+        return NULL;
+    }
+    PyObject *result =3D meth(args[0], args+1, nargs-1);
+    Py_LeaveRecursiveCall();
+    return result;
+}
+
+static PyObject *
+method_vectorcall_FASTCALL_KEYWORDS(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
+{
+    Py_ssize_t nargs =3D PyVectorcall_NARGS(nargsf);
+    if (method_check_args(func, args, nargs, NULL)) {
+        return NULL;
+    }
+    _PyCFunctionFastWithKeywords meth =3D (_PyCFunctionFastWithKeywords)
+                                        method_enter_call(func);
+    if (meth =3D=3D NULL) {
+        return NULL;
+    }
+    PyObject *result =3D meth(args[0], args+1, nargs-1, kwnames);
+    Py_LeaveRecursiveCall();
+    return result;
+}
+
+static PyObject *
+method_vectorcall_NOARGS(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
+{
+    Py_ssize_t nargs =3D PyVectorcall_NARGS(nargsf);
+    if (method_check_args(func, args, nargs, kwnames)) {
+        return NULL;
+    }
+    if (nargs !=3D 1) {
         PyErr_Format(PyExc_TypeError,
-                     "descriptor '%V' for '%.100s' objects "
-                     "doesn't apply to a '%.100s' object",
-                     descr_name((PyDescrObject *)descr), "?",
-                     PyDescr_TYPE(descr)->tp_name,
-                     self->ob_type->tp_name);
+            "%.200s() takes no arguments (%zd given)", get_name(func), nargs=
-1);
         return NULL;
     }
+    PyCFunction meth =3D (PyCFunction)method_enter_call(func);
+    if (meth =3D=3D NULL) {
+        return NULL;
+    }
+    PyObject *result =3D meth(args[0], NULL);
+    Py_LeaveRecursiveCall();
+    return result;
+}
=20
-    result =3D _PyMethodDef_RawFastCallKeywords(descr->d_method, self,
-                                              args+1, nargs-1, kwnames);
-    result =3D _Py_CheckFunctionResult((PyObject *)descr, result, NULL);
+static PyObject *
+method_vectorcall_O(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
+{
+    Py_ssize_t nargs =3D PyVectorcall_NARGS(nargsf);
+    if (method_check_args(func, args, nargs, kwnames)) {
+        return NULL;
+    }
+    if (nargs !=3D 2) {
+        PyErr_Format(PyExc_TypeError,
+            "%.200s() takes exactly one argument (%zd given)",
+            get_name(func), nargs-1);
+        return NULL;
+    }
+    PyCFunction meth =3D (PyCFunction)method_enter_call(func);
+    if (meth =3D=3D NULL) {
+        return NULL;
+    }
+    PyObject *result =3D meth(args[0], args[1]);
+    Py_LeaveRecursiveCall();
     return result;
 }
=20
+
 static PyObject *
 classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
                       PyObject *kwds)
@@ -552,7 +671,7 @@ PyTypeObject PyMethodDescr_Type =3D {
     0,                                          /* tp_as_sequence */
     0,                                          /* tp_as_mapping */
     0,                                          /* tp_hash */
-    (ternaryfunc)methoddescr_call,              /* tp_call */
+    PyVectorcall_Call,                          /* tp_call */
     0,                                          /* tp_str */
     PyObject_GenericGetAttr,                    /* tp_getattro */
     0,                                          /* tp_setattro */
@@ -750,13 +869,40 @@ descr_new(PyTypeObject *descrtype, PyTypeObject *type, =
const char *name)
 PyObject *
 PyDescr_NewMethod(PyTypeObject *type, PyMethodDef *method)
 {
+    /* Figure out correct vectorcall function to use */
+    vectorcallfunc vectorcall;
+    switch (method->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS |=
 METH_O | METH_KEYWORDS))
+    {
+        case METH_VARARGS:
+            vectorcall =3D method_vectorcall_VARARGS;
+            break;
+        case METH_VARARGS | METH_KEYWORDS:
+            vectorcall =3D method_vectorcall_VARARGS_KEYWORDS;
+            break;
+        case METH_FASTCALL:
+            vectorcall =3D method_vectorcall_FASTCALL;
+            break;
+        case METH_FASTCALL | METH_KEYWORDS:
+            vectorcall =3D method_vectorcall_FASTCALL_KEYWORDS;
+            break;
+        case METH_NOARGS:
+            vectorcall =3D method_vectorcall_NOARGS;
+            break;
+        case METH_O:
+            vectorcall =3D method_vectorcall_O;
+            break;
+        default:
+            PyErr_SetString(PyExc_SystemError, "bad call flags");
+            return NULL;
+    }
+
     PyMethodDescrObject *descr;
=20
     descr =3D (PyMethodDescrObject *)descr_new(&PyMethodDescr_Type,
                                              type, method->ml_name);
     if (descr !=3D NULL) {
         descr->d_method =3D method;
-        descr->vectorcall =3D _PyMethodDescr_Vectorcall;
+        descr->vectorcall =3D vectorcall;
     }
     return (PyObject *)descr;
 }
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index c3bc0184796e..3494f11d80fe 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -19,6 +19,17 @@ static int numfree =3D 0;
 /* undefine macro trampoline to PyCFunction_NewEx */
 #undef PyCFunction_New
=20
+/* Forward declarations */
+static PyObject * cfunction_vectorcall_FASTCALL(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
+static PyObject * cfunction_vectorcall_FASTCALL_KEYWORDS(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
+static PyObject * cfunction_vectorcall_NOARGS(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
+static PyObject * cfunction_vectorcall_O(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
+
+
 PyObject *
 PyCFunction_New(PyMethodDef *ml, PyObject *self)
 {
@@ -28,6 +39,33 @@ PyCFunction_New(PyMethodDef *ml, PyObject *self)
 PyObject *
 PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
 {
+    /* Figure out correct vectorcall function to use */
+    vectorcallfunc vectorcall;
+    switch (ml->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | MET=
H_O | METH_KEYWORDS))
+    {
+        case METH_VARARGS:
+        case METH_VARARGS | METH_KEYWORDS:
+            /* For METH_VARARGS functions, it's more efficient to use tp_call
+             * instead of vectorcall. */
+            vectorcall =3D NULL;
+            break;
+        case METH_FASTCALL:
+            vectorcall =3D cfunction_vectorcall_FASTCALL;
+            break;
+        case METH_FASTCALL | METH_KEYWORDS:
+            vectorcall =3D cfunction_vectorcall_FASTCALL_KEYWORDS;
+            break;
+        case METH_NOARGS:
+            vectorcall =3D cfunction_vectorcall_NOARGS;
+            break;
+        case METH_O:
+            vectorcall =3D cfunction_vectorcall_O;
+            break;
+        default:
+            PyErr_SetString(PyExc_SystemError, "bad call flags");
+            return NULL;
+    }
+
     PyCFunctionObject *op;
     op =3D free_list;
     if (op !=3D NULL) {
@@ -46,14 +84,7 @@ PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObjec=
t *module)
     op->m_self =3D self;
     Py_XINCREF(module);
     op->m_module =3D module;
-    if (ml->ml_flags & METH_VARARGS) {
-        /* For METH_VARARGS functions, it's more efficient to use tp_call
-         * instead of vectorcall. */
-        op->vectorcall =3D NULL;
-    }
-    else {
-        op->vectorcall =3D _PyCFunction_Vectorcall;
-    }
+    op->vectorcall =3D vectorcall;
     _PyObject_GC_TRACK(op);
     return (PyObject *)op;
 }
@@ -333,3 +364,121 @@ _PyCFunction_DebugMallocStats(FILE *out)
                            "free PyCFunctionObject",
                            numfree, sizeof(PyCFunctionObject));
 }
+
+
+/* Vectorcall functions for each of the PyCFunction calling conventions,
+ * except for METH_VARARGS (possibly combined with METH_KEYWORDS) which
+ * doesn't use vectorcall.
+ *
+ * First, common helpers
+ */
+static const char *
+get_name(PyObject *func)
+{
+    assert(PyCFunction_Check(func));
+    PyMethodDef *method =3D ((PyCFunctionObject *)func)->m_ml;
+    return method->ml_name;
+}
+
+typedef void (*funcptr)(void);
+
+static inline int
+cfunction_check_kwargs(PyObject *func, PyObject *kwnames)
+{
+    assert(!PyErr_Occurred());
+    assert(PyCFunction_Check(func));
+    if (kwnames && PyTuple_GET_SIZE(kwnames)) {
+        PyErr_Format(PyExc_TypeError,
+                     "%.200s() takes no keyword arguments", get_name(func));
+        return -1;
+    }
+    return 0;
+}
+
+static inline funcptr
+cfunction_enter_call(PyObject *func)
+{
+    if (Py_EnterRecursiveCall(" while calling a Python object")) {
+        return NULL;
+    }
+    return (funcptr)PyCFunction_GET_FUNCTION(func);
+}
+
+/* Now the actual vectorcall functions */
+static PyObject *
+cfunction_vectorcall_FASTCALL(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
+{
+    if (cfunction_check_kwargs(func, kwnames)) {
+        return NULL;
+    }
+    Py_ssize_t nargs =3D PyVectorcall_NARGS(nargsf);
+    _PyCFunctionFast meth =3D (_PyCFunctionFast)
+                            cfunction_enter_call(func);
+    if (meth =3D=3D NULL) {
+        return NULL;
+    }
+    PyObject *result =3D meth(PyCFunction_GET_SELF(func), args, nargs);
+    Py_LeaveRecursiveCall();
+    return result;
+}
+
+static PyObject *
+cfunction_vectorcall_FASTCALL_KEYWORDS(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
+{
+    Py_ssize_t nargs =3D PyVectorcall_NARGS(nargsf);
+    _PyCFunctionFastWithKeywords meth =3D (_PyCFunctionFastWithKeywords)
+                                        cfunction_enter_call(func);
+    if (meth =3D=3D NULL) {
+        return NULL;
+    }
+    PyObject *result =3D meth(PyCFunction_GET_SELF(func), args, nargs, kwnam=
es);
+    Py_LeaveRecursiveCall();
+    return result;
+}
+
+static PyObject *
+cfunction_vectorcall_NOARGS(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
+{
+    if (cfunction_check_kwargs(func, kwnames)) {
+        return NULL;
+    }
+    Py_ssize_t nargs =3D PyVectorcall_NARGS(nargsf);
+    if (nargs !=3D 0) {
+        PyErr_Format(PyExc_TypeError,
+            "%.200s() takes no arguments (%zd given)", get_name(func), nargs=
);
+        return NULL;
+    }
+    PyCFunction meth =3D (PyCFunction)cfunction_enter_call(func);
+    if (meth =3D=3D NULL) {
+        return NULL;
+    }
+    PyObject *result =3D meth(PyCFunction_GET_SELF(func), NULL);
+    Py_LeaveRecursiveCall();
+    return result;
+}
+
+static PyObject *
+cfunction_vectorcall_O(
+    PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
+{
+    if (cfunction_check_kwargs(func, kwnames)) {
+        return NULL;
+    }
+    Py_ssize_t nargs =3D PyVectorcall_NARGS(nargsf);
+    if (nargs !=3D 1) {
+        PyErr_Format(PyExc_TypeError,
+            "%.200s() takes exactly one argument (%zd given)",
+            get_name(func), nargs);
+        return NULL;
+    }
+    PyCFunction meth =3D (PyCFunction)cfunction_enter_call(func);
+    if (meth =3D=3D NULL) {
+        return NULL;
+    }
+    PyObject *result =3D meth(PyCFunction_GET_SELF(func), args[0]);
+    Py_LeaveRecursiveCall();
+    return result;
+}
diff --git a/Python/ceval.c b/Python/ceval.c
index eddcc8d8b4d4..546a4264d8ad 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4943,7 +4943,7 @@ trace_call_function(PyThreadState *tstate,
 {
     PyObject *x;
     if (PyCFunction_Check(func)) {
-        C_TRACE(x, _PyCFunction_Vectorcall(func, args, nargs, kwnames));
+        C_TRACE(x, _PyObject_Vectorcall(func, args, nargs, kwnames));
         return x;
     }
     else if (Py_TYPE(func) =3D=3D &PyMethodDescr_Type && nargs > 0) {
@@ -4959,9 +4959,9 @@ trace_call_function(PyThreadState *tstate,
         if (func =3D=3D NULL) {
             return NULL;
         }
-        C_TRACE(x, _PyCFunction_Vectorcall(func,
-                                           args+1, nargs-1,
-                                           kwnames));
+        C_TRACE(x, _PyObject_Vectorcall(func,
+                                        args+1, nargs-1,
+                                        kwnames));
         Py_DECREF(func);
         return x;
     }
@@ -5023,10 +5023,10 @@ do_call_core(PyThreadState *tstate, PyObject *func, P=
yObject *callargs, PyObject
                 return NULL;
             }
=20
-            C_TRACE(result, _PyCFunction_FastCallDict(func,
-                                                      &_PyTuple_ITEMS(callar=
gs)[1],
-                                                      nargs - 1,
-                                                      kwdict));
+            C_TRACE(result, _PyObject_FastCallDict(func,
+                                                   &_PyTuple_ITEMS(callargs)=
[1],
+                                                   nargs - 1,
+                                                   kwdict));
             Py_DECREF(func);
             return result;
         }
diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py
index 93f720ab7e2a..e40f79b5c3c7 100755
--- a/Tools/gdb/libpython.py
+++ b/Tools/gdb/libpython.py
@@ -1563,9 +1563,8 @@ def is_other_python_frame(self):
         if not caller:
             return False
=20
-        if caller in ('_PyCFunction_FastCallDict',
-                      '_PyCFunction_Vectorcall',
-                      'cfunction_call_varargs'):
+        if (caller.startswith('cfunction_vectorcall_') or
+            caller =3D=3D 'cfunction_call_varargs'):
             arg_name =3D 'func'
             # Within that frame:
             #   "func" is the local containing the PyObject* of the



More information about the Python-checkins mailing list