bpo-39245: Switch to public API for Vectorcall (GH-18460)

The bulk of this patch was generated automatically with:

    for name in \
        PyObject_Vectorcall \
        Py_TPFLAGS_HAVE_VECTORCALL \
        PyObject_VectorcallMethod \
        PyVectorcall_Function \
        PyObject_CallOneArg \
        PyObject_CallMethodNoArgs \
        PyObject_CallMethodOneArg \
    ;
    do
        echo $name
        git grep -lwz _$name | xargs -0 sed -i "s/\b_$name\b/$name/g"
    done

    old=_PyObject_FastCallDict
    new=PyObject_VectorcallDict
    git grep -lwz $old | xargs -0 sed -i "s/\b$old\b/$new/g"

and then cleaned up:

- Revert changes to in docs & news
- Revert changes to backcompat defines in headers
- Nudge misaligned comments
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 7ab58a8..f0e01f7 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -179,7 +179,7 @@
             return NULL;
         }
         if (meth) {
-            result = _PyObject_CallOneArg(meth, key);
+            result = PyObject_CallOneArg(meth, key);
             Py_DECREF(meth);
             return result;
         }
@@ -780,7 +780,7 @@
     }
 
     /* And call it. */
-    result = _PyObject_CallOneArg(meth, format_spec);
+    result = PyObject_CallOneArg(meth, format_spec);
     Py_DECREF(meth);
 
     if (result && !PyUnicode_Check(result)) {
@@ -2502,7 +2502,7 @@
             return -1;
         }
 
-        PyObject *res = _PyObject_CallOneArg(checker, inst);
+        PyObject *res = PyObject_CallOneArg(checker, inst);
         _Py_LeaveRecursiveCall(tstate);
         Py_DECREF(checker);
 
@@ -2588,7 +2588,7 @@
             Py_DECREF(checker);
             return ok;
         }
-        PyObject *res = _PyObject_CallOneArg(checker, derived);
+        PyObject *res = PyObject_CallOneArg(checker, derived);
         _Py_LeaveRecursiveCall(tstate);
         Py_DECREF(checker);
         if (res != NULL) {
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index b2808c0..a3fc35c 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -89,7 +89,7 @@
 PyObject *
 PyByteArray_FromObject(PyObject *input)
 {
-    return _PyObject_CallOneArg((PyObject *)&PyByteArray_Type, input);
+    return PyObject_CallOneArg((PyObject *)&PyByteArray_Type, input);
 }
 
 static PyObject *
@@ -2015,7 +2015,7 @@
 {
     PyObject *result = _PyBytes_FromHex(string, type == &PyByteArray_Type);
     if (type != &PyByteArray_Type && result != NULL) {
-        Py_SETREF(result, _PyObject_CallOneArg((PyObject *)type, result));
+        Py_SETREF(result, PyObject_CallOneArg((PyObject *)type, result));
     }
     return result;
 }
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index e139bed..df3edda 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -2259,7 +2259,7 @@
 {
     PyObject *result = _PyBytes_FromHex(string, 0);
     if (type != &PyBytes_Type && result != NULL) {
-        Py_SETREF(result, _PyObject_CallOneArg((PyObject *)type, result));
+        Py_SETREF(result, PyObject_CallOneArg((PyObject *)type, result));
     }
     return result;
 }
diff --git a/Objects/call.c b/Objects/call.c
index d1d50b6..37d079d 100644
--- a/Objects/call.c
+++ b/Objects/call.c
@@ -95,7 +95,7 @@
 {
     assert(callable != NULL);
 
-    /* _PyObject_FastCallDict() must not be called with an exception set,
+    /* PyObject_VectorcallDict() must not be called with an exception set,
        because it can clear it (directly or indirectly) and so the
        caller loses its exception */
     assert(!_PyErr_Occurred(tstate));
@@ -105,7 +105,7 @@
     assert(nargs == 0 || args != NULL);
     assert(kwargs == NULL || PyDict_Check(kwargs));
 
-    vectorcallfunc func = _PyVectorcall_Function(callable);
+    vectorcallfunc func = PyVectorcall_Function(callable);
     if (func == NULL) {
         /* Use tp_call instead */
         return _PyObject_MakeTpCall(tstate, callable, args, nargs, kwargs);
@@ -133,7 +133,7 @@
 
 
 PyObject *
-_PyObject_FastCallDict(PyObject *callable, PyObject *const *args,
+PyObject_VectorcallDict(PyObject *callable, PyObject *const *args,
                        size_t nargsf, PyObject *kwargs)
 {
     PyThreadState *tstate = _PyThreadState_GET();
@@ -204,8 +204,8 @@
 {
     PyThreadState *tstate = _PyThreadState_GET();
 
-    /* get vectorcallfunc as in _PyVectorcall_Function, but without
-     * the _Py_TPFLAGS_HAVE_VECTORCALL check */
+    /* get vectorcallfunc as in PyVectorcall_Function, but without
+     * the Py_TPFLAGS_HAVE_VECTORCALL check */
     Py_ssize_t offset = Py_TYPE(callable)->tp_vectorcall_offset;
     if (offset <= 0) {
         _PyErr_Format(tstate, PyExc_TypeError,
@@ -259,7 +259,7 @@
     assert(PyTuple_Check(args));
     assert(kwargs == NULL || PyDict_Check(kwargs));
 
-    if (_PyVectorcall_Function(callable) != NULL) {
+    if (PyVectorcall_Function(callable) != NULL) {
         return PyVectorcall_Call(callable, args, kwargs);
     }
     else {
@@ -796,7 +796,7 @@
 
 
 PyObject *
-_PyObject_VectorcallMethod(PyObject *name, PyObject *const *args,
+PyObject_VectorcallMethod(PyObject *name, PyObject *const *args,
                            size_t nargsf, PyObject *kwnames)
 {
     assert(name != NULL);
diff --git a/Objects/classobject.c b/Objects/classobject.c
index fb89b8a..33afbcd 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -350,7 +350,7 @@
     PyObject_GenericSetAttr,                    /* tp_setattro */
     0,                                          /* tp_as_buffer */
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
-    _Py_TPFLAGS_HAVE_VECTORCALL,                /* tp_flags */
+    Py_TPFLAGS_HAVE_VECTORCALL,                 /* tp_flags */
     method_doc,                                 /* tp_doc */
     (traverseproc)method_traverse,              /* tp_traverse */
     0,                                          /* tp_clear */
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 49c26eb..aaaa447 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -454,7 +454,7 @@
     if (bound == NULL) {
         return NULL;
     }
-    PyObject *res = _PyObject_FastCallDict(bound, _PyTuple_ITEMS(args)+1,
+    PyObject *res = PyObject_VectorcallDict(bound, _PyTuple_ITEMS(args)+1,
                                            argc-1, kwds);
     Py_DECREF(bound);
     return res;
@@ -673,7 +673,7 @@
     0,                                          /* tp_setattro */
     0,                                          /* tp_as_buffer */
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
-    _Py_TPFLAGS_HAVE_VECTORCALL |
+    Py_TPFLAGS_HAVE_VECTORCALL |
     Py_TPFLAGS_METHOD_DESCRIPTOR,               /* tp_flags */
     0,                                          /* tp_doc */
     descr_traverse,                             /* tp_traverse */
@@ -1493,7 +1493,7 @@
         return NULL;
     }
 
-    return _PyObject_CallOneArg(gs->prop_get, obj);
+    return PyObject_CallOneArg(gs->prop_get, obj);
 }
 
 static int
@@ -1514,7 +1514,7 @@
         return -1;
     }
     if (value == NULL)
-        res = _PyObject_CallOneArg(func, obj);
+        res = PyObject_CallOneArg(func, obj);
     else
         res = PyObject_CallFunctionObjArgs(func, obj, value, NULL);
     if (res == NULL)
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 164104e..8f6ce39 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -2127,7 +2127,7 @@
             _Py_IDENTIFIER(__missing__);
             missing = _PyObject_LookupSpecial((PyObject *)mp, &PyId___missing__);
             if (missing != NULL) {
-                res = _PyObject_CallOneArg(missing, key);
+                res = PyObject_CallOneArg(missing, key);
                 Py_DECREF(missing);
                 return res;
             }
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index c0eff8b..840d17b 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -137,7 +137,7 @@
         Py_DECREF(writer);
         return -1;
     }
-    result = _PyObject_CallOneArg(writer, value);
+    result = PyObject_CallOneArg(writer, value);
     Py_DECREF(value);
     Py_DECREF(writer);
     if (result == NULL)
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index dfc5b19..648030b 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1490,7 +1490,7 @@
         goto parse_error;
     result = PyFloat_FromDouble(negate ? -x : x);
     if (type != &PyFloat_Type && result != NULL) {
-        Py_SETREF(result, _PyObject_CallOneArg((PyObject *)type, result));
+        Py_SETREF(result, PyObject_CallOneArg((PyObject *)type, result));
     }
     return result;
 
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index ebe68ad..419db33 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -654,7 +654,7 @@
     0,                                          /* tp_setattro */
     0,                                          /* tp_as_buffer */
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
-    _Py_TPFLAGS_HAVE_VECTORCALL |
+    Py_TPFLAGS_HAVE_VECTORCALL |
     Py_TPFLAGS_METHOD_DESCRIPTOR,               /* tp_flags */
     func_new__doc__,                            /* tp_doc */
     (traverseproc)func_traverse,                /* tp_traverse */
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 652c290..576d685 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -58,7 +58,7 @@
             /* Save the current exception, if any. */
             PyErr_Fetch(&error_type, &error_value, &error_traceback);
 
-            res = _PyObject_CallOneArg(finalizer, self);
+            res = PyObject_CallOneArg(finalizer, self);
 
             if (res == NULL) {
                 PyErr_WriteUnraisable(self);
@@ -563,7 +563,7 @@
         return 0;
     }
     /* Construct an exception instance manually with
-     * _PyObject_CallOneArg and pass it to PyErr_SetObject.
+     * PyObject_CallOneArg and pass it to PyErr_SetObject.
      *
      * We do this to handle a situation when "value" is a tuple, in which
      * case PyErr_SetObject would set the value of StopIteration to
@@ -571,7 +571,7 @@
      *
      * (See PyErr_SetObject/_PyErr_CreateException code for details.)
      */
-    e = _PyObject_CallOneArg(PyExc_StopIteration, value);
+    e = PyObject_CallOneArg(PyExc_StopIteration, value);
     if (e == NULL) {
         return -1;
     }
@@ -1264,7 +1264,7 @@
         PyObject *res;
 
         Py_INCREF(firstiter);
-        res = _PyObject_CallOneArg(firstiter, (PyObject *)o);
+        res = PyObject_CallOneArg(firstiter, (PyObject *)o);
         Py_DECREF(firstiter);
         if (res == NULL) {
             return 1;
diff --git a/Objects/listobject.c b/Objects/listobject.c
index a406e70..3c39c64 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2226,7 +2226,7 @@
         }
 
         for (i = 0; i < saved_ob_size ; i++) {
-            keys[i] = _PyObject_CallOneArg(keyfunc, saved_ob_item[i]);
+            keys[i] = PyObject_CallOneArg(keyfunc, saved_ob_item[i]);
             if (keys[i] == NULL) {
                 for (i=i-1 ; i>=0 ; i--)
                     Py_DECREF(keys[i]);
diff --git a/Objects/longobject.c b/Objects/longobject.c
index b4d0b05..5d225cb 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -5547,7 +5547,7 @@
     Py_DECREF(bytes);
 
     if (long_obj != NULL && type != &PyLong_Type) {
-        Py_SETREF(long_obj, _PyObject_CallOneArg((PyObject *)type, long_obj));
+        Py_SETREF(long_obj, PyObject_CallOneArg((PyObject *)type, long_obj));
     }
 
     return long_obj;
diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c
index d9dd117..906d1ce 100644
--- a/Objects/memoryobject.c
+++ b/Objects/memoryobject.c
@@ -1963,7 +1963,7 @@
     if (format == NULL)
         goto error;
 
-    structobj = _PyObject_CallOneArg(Struct, format);
+    structobj = PyObject_CallOneArg(Struct, format);
     if (structobj == NULL)
         goto error;
 
@@ -2002,7 +2002,7 @@
     PyObject *v;
 
     memcpy(x->item, ptr, x->itemsize);
-    v = _PyObject_CallOneArg(x->unpack_from, x->mview);
+    v = PyObject_CallOneArg(x->unpack_from, x->mview);
     if (v == NULL)
         return NULL;
 
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index 2a8111f..1d54c4c 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -298,7 +298,7 @@
     0,                                          /* tp_setattro */
     0,                                          /* tp_as_buffer */
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
-    _Py_TPFLAGS_HAVE_VECTORCALL,                /* tp_flags */
+    Py_TPFLAGS_HAVE_VECTORCALL,                 /* tp_flags */
     0,                                          /* tp_doc */
     (traverseproc)meth_traverse,                /* tp_traverse */
     0,                                          /* tp_clear */
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 0a59326..30de53d 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -738,7 +738,7 @@
         _Py_IDENTIFIER(__getattr__);
         getattr = _PyDict_GetItemId(m->md_dict, &PyId___getattr__);
         if (getattr) {
-            return _PyObject_CallOneArg(getattr, name);
+            return PyObject_CallOneArg(getattr, name);
         }
         mod_name = _PyDict_GetItemId(m->md_dict, &PyId___name__);
         if (mod_name && PyUnicode_Check(mod_name)) {
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index e6a84b0..f32ccb1 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1465,7 +1465,7 @@
 call_unbound_noarg(int unbound, PyObject *func, PyObject *self)
 {
     if (unbound) {
-        return _PyObject_CallOneArg(func, self);
+        return PyObject_CallOneArg(func, self);
     }
     else {
         return _PyObject_CallNoArg(func);
@@ -3665,7 +3665,7 @@
     0,                                          /* tp_as_buffer */
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
     Py_TPFLAGS_BASETYPE | Py_TPFLAGS_TYPE_SUBCLASS |
-    _Py_TPFLAGS_HAVE_VECTORCALL,                /* tp_flags */
+    Py_TPFLAGS_HAVE_VECTORCALL,                 /* tp_flags */
     type_doc,                                   /* tp_doc */
     (traverseproc)type_traverse,                /* tp_traverse */
     (inquiry)type_clear,                        /* tp_clear */
@@ -5196,17 +5196,17 @@
     /* tp_hash see tp_richcompare */
     {
         /* Always inherit tp_vectorcall_offset to support PyVectorcall_Call().
-         * If _Py_TPFLAGS_HAVE_VECTORCALL is not inherited, then vectorcall
+         * If Py_TPFLAGS_HAVE_VECTORCALL is not inherited, then vectorcall
          * won't be used automatically. */
         COPYSLOT(tp_vectorcall_offset);
 
-        /* Inherit _Py_TPFLAGS_HAVE_VECTORCALL for non-heap types
+        /* Inherit Py_TPFLAGS_HAVE_VECTORCALL for non-heap types
         * if tp_call is not overridden */
         if (!type->tp_call &&
-            (base->tp_flags & _Py_TPFLAGS_HAVE_VECTORCALL) &&
+            (base->tp_flags & Py_TPFLAGS_HAVE_VECTORCALL) &&
             !(type->tp_flags & Py_TPFLAGS_HEAPTYPE))
         {
-            type->tp_flags |= _Py_TPFLAGS_HAVE_VECTORCALL;
+            type->tp_flags |= Py_TPFLAGS_HAVE_VECTORCALL;
         }
         COPYSLOT(tp_call);
     }
@@ -5282,14 +5282,14 @@
 
     /* Consistency checks for PEP 590:
      * - Py_TPFLAGS_METHOD_DESCRIPTOR requires tp_descr_get
-     * - _Py_TPFLAGS_HAVE_VECTORCALL requires tp_call and
+     * - Py_TPFLAGS_HAVE_VECTORCALL requires tp_call and
      *   tp_vectorcall_offset > 0
      * To avoid mistakes, we require this before inheriting.
      */
     if (type->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR) {
         _PyObject_ASSERT((PyObject *)type, type->tp_descr_get != NULL);
     }
-    if (type->tp_flags & _Py_TPFLAGS_HAVE_VECTORCALL) {
+    if (type->tp_flags & Py_TPFLAGS_HAVE_VECTORCALL) {
         _PyObject_ASSERT((PyObject *)type, type->tp_vectorcall_offset > 0);
         _PyObject_ASSERT((PyObject *)type, type->tp_call != NULL);
     }
@@ -6614,7 +6614,7 @@
         else
             attr = descr;
     }
-    res = _PyObject_CallOneArg(attr, name);
+    res = PyObject_CallOneArg(attr, name);
     Py_XDECREF(descr);
     return res;
 }
@@ -7575,7 +7575,7 @@
     }
 
 
-    result = _PyObject_FastCallDict(func, NULL, 0, kwds);
+    result = PyObject_VectorcallDict(func, NULL, 0, kwds);
     Py_DECREF(func);
     if (result == NULL) {
         return -1;
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index aa874f2..68e4f6a 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -4250,7 +4250,7 @@
     if (*exceptionObject == NULL)
         goto onError;
 
-    restuple = _PyObject_CallOneArg(*errorHandler, *exceptionObject);
+    restuple = PyObject_CallOneArg(*errorHandler, *exceptionObject);
     if (restuple == NULL)
         goto onError;
     if (!PyTuple_Check(restuple)) {
@@ -4354,7 +4354,7 @@
     if (*exceptionObject == NULL)
         goto onError;
 
-    restuple = _PyObject_CallOneArg(*errorHandler, *exceptionObject);
+    restuple = PyObject_CallOneArg(*errorHandler, *exceptionObject);
     if (restuple == NULL)
         goto onError;
     if (!PyTuple_Check(restuple)) {
@@ -6801,7 +6801,7 @@
     if (*exceptionObject == NULL)
         return NULL;
 
-    restuple = _PyObject_CallOneArg(*errorHandler, *exceptionObject);
+    restuple = PyObject_CallOneArg(*errorHandler, *exceptionObject);
     if (restuple == NULL)
         return NULL;
     if (!PyTuple_Check(restuple)) {
@@ -8783,7 +8783,7 @@
     if (*exceptionObject == NULL)
         return NULL;
 
-    restuple = _PyObject_CallOneArg(*errorHandler, *exceptionObject);
+    restuple = PyObject_CallOneArg(*errorHandler, *exceptionObject);
     if (restuple == NULL)
         return NULL;
     if (!PyTuple_Check(restuple)) {
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c
index 18c737e..7a5d9fb 100644
--- a/Objects/weakrefobject.c
+++ b/Objects/weakrefobject.c
@@ -933,7 +933,7 @@
 static void
 handle_callback(PyWeakReference *ref, PyObject *callback)
 {
-    PyObject *cbresult = _PyObject_CallOneArg(callback, (PyObject *)ref);
+    PyObject *cbresult = PyObject_CallOneArg(callback, (PyObject *)ref);
 
     if (cbresult == NULL)
         PyErr_WriteUnraisable(callback);