Skip to content

Commit ffd9753

Browse files
authored
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
1 parent f3e7ea5 commit ffd9753

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+194
-194
lines changed

Include/cpython/abstract.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ PyVectorcall_Function(PyObject *callable)
6767
{
6868
assert(callable != NULL);
6969
PyTypeObject *tp = Py_TYPE(callable);
70-
if (!PyType_HasFeature(tp, _Py_TPFLAGS_HAVE_VECTORCALL)) {
70+
if (!PyType_HasFeature(tp, Py_TPFLAGS_HAVE_VECTORCALL)) {
7171
return NULL;
7272
}
7373
assert(PyCallable_Check(callable));
@@ -178,7 +178,7 @@ PyAPI_FUNC(PyObject *) PyObject_VectorcallMethod(
178178
static inline PyObject *
179179
PyObject_CallMethodNoArgs(PyObject *self, PyObject *name)
180180
{
181-
return _PyObject_VectorcallMethod(name, &self,
181+
return PyObject_VectorcallMethod(name, &self,
182182
1 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
183183
}
184184

@@ -187,7 +187,7 @@ PyObject_CallMethodOneArg(PyObject *self, PyObject *name, PyObject *arg)
187187
{
188188
assert(arg != NULL);
189189
PyObject *args[2] = {self, arg};
190-
return _PyObject_VectorcallMethod(name, args,
190+
return PyObject_VectorcallMethod(name, args,
191191
2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
192192
}
193193

Lib/test/test_call.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def test_fastcall(self):
468468
self.check_result(result, expected)
469469

470470
def test_vectorcall_dict(self):
471-
# Test _PyObject_FastCallDict()
471+
# Test PyObject_VectorcallDict()
472472

473473
for func, args, expected in self.CALLS_POSARGS:
474474
with self.subTest(func=func, args=args):
@@ -487,7 +487,7 @@ def test_vectorcall_dict(self):
487487
self.check_result(result, expected)
488488

489489
def test_vectorcall(self):
490-
# Test _PyObject_Vectorcall()
490+
# Test PyObject_Vectorcall()
491491

492492
for func, args, expected in self.CALLS_POSARGS:
493493
with self.subTest(func=func, args=args):
@@ -594,7 +594,7 @@ def test_vectorcall(self):
594594
# 1. vectorcall using PyVectorcall_Call()
595595
# (only for objects that support vectorcall directly)
596596
# 2. normal call
597-
# 3. vectorcall using _PyObject_Vectorcall()
597+
# 3. vectorcall using PyObject_Vectorcall()
598598
# 4. call as bound method
599599
# 5. call using functools.partial
600600

Modules/_asynciomodule.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ _is_coroutine(PyObject *coro)
142142
Do this check after 'future_init()'; in case we need to raise
143143
an error, __del__ needs a properly initialized object.
144144
*/
145-
PyObject *res = _PyObject_CallOneArg(asyncio_iscoroutine_func, coro);
145+
PyObject *res = PyObject_CallOneArg(asyncio_iscoroutine_func, coro);
146146
if (res == NULL) {
147147
return -1;
148148
}
@@ -367,7 +367,7 @@ call_soon(PyObject *loop, PyObject *func, PyObject *arg, PyObject *ctx)
367367
}
368368
stack[nargs] = (PyObject *)ctx;
369369

370-
handle = _PyObject_Vectorcall(callable, stack, nargs, context_kwname);
370+
handle = PyObject_Vectorcall(callable, stack, nargs, context_kwname);
371371
Py_DECREF(callable);
372372
}
373373

@@ -1287,7 +1287,7 @@ static PyObject *
12871287
_asyncio_Future__repr_info_impl(FutureObj *self)
12881288
/*[clinic end generated code: output=fa69e901bd176cfb input=f21504d8e2ae1ca2]*/
12891289
{
1290-
return _PyObject_CallOneArg(asyncio_future_repr_info_func, (PyObject *)self);
1290+
return PyObject_CallOneArg(asyncio_future_repr_info_func, (PyObject *)self);
12911291
}
12921292

12931293
static PyObject *
@@ -1363,7 +1363,7 @@ FutureObj_finalize(FutureObj *fut)
13631363

13641364
func = _PyObject_GetAttrId(fut->fut_loop, &PyId_call_exception_handler);
13651365
if (func != NULL) {
1366-
PyObject *res = _PyObject_CallOneArg(func, context);
1366+
PyObject *res = PyObject_CallOneArg(func, context);
13671367
if (res == NULL) {
13681368
PyErr_WriteUnraisable(func);
13691369
}
@@ -2126,13 +2126,13 @@ _asyncio_Task_current_task_impl(PyTypeObject *type, PyObject *loop)
21262126
Py_DECREF(current_task_func);
21272127
return NULL;
21282128
}
2129-
ret = _PyObject_CallOneArg(current_task_func, loop);
2129+
ret = PyObject_CallOneArg(current_task_func, loop);
21302130
Py_DECREF(current_task_func);
21312131
Py_DECREF(loop);
21322132
return ret;
21332133
}
21342134
else {
2135-
ret = _PyObject_CallOneArg(current_task_func, loop);
2135+
ret = PyObject_CallOneArg(current_task_func, loop);
21362136
Py_DECREF(current_task_func);
21372137
return ret;
21382138
}
@@ -2168,7 +2168,7 @@ _asyncio_Task_all_tasks_impl(PyTypeObject *type, PyObject *loop)
21682168
return NULL;
21692169
}
21702170

2171-
res = _PyObject_CallOneArg(all_tasks_func, loop);
2171+
res = PyObject_CallOneArg(all_tasks_func, loop);
21722172
Py_DECREF(all_tasks_func);
21732173
return res;
21742174
}
@@ -2181,7 +2181,7 @@ static PyObject *
21812181
_asyncio_Task__repr_info_impl(TaskObj *self)
21822182
/*[clinic end generated code: output=6a490eb66d5ba34b input=3c6d051ed3ddec8b]*/
21832183
{
2184-
return _PyObject_CallOneArg(asyncio_task_repr_info_func, (PyObject *)self);
2184+
return PyObject_CallOneArg(asyncio_task_repr_info_func, (PyObject *)self);
21852185
}
21862186

21872187
/*[clinic input]
@@ -2431,7 +2431,7 @@ TaskObj_finalize(TaskObj *task)
24312431

24322432
func = _PyObject_GetAttrId(task->task_loop, &PyId_call_exception_handler);
24332433
if (func != NULL) {
2434-
PyObject *res = _PyObject_CallOneArg(func, context);
2434+
PyObject *res = PyObject_CallOneArg(func, context);
24352435
if (res == NULL) {
24362436
PyErr_WriteUnraisable(func);
24372437
}
@@ -2571,7 +2571,7 @@ task_set_error_soon(TaskObj *task, PyObject *et, const char *format, ...)
25712571
return NULL;
25722572
}
25732573

2574-
PyObject *e = _PyObject_CallOneArg(et, msg);
2574+
PyObject *e = PyObject_CallOneArg(et, msg);
25752575
Py_DECREF(msg);
25762576
if (e == NULL) {
25772577
return NULL;
@@ -2841,7 +2841,7 @@ task_step_impl(TaskObj *task, PyObject *exc)
28412841
PyObject *stack[2];
28422842
stack[0] = wrapper;
28432843
stack[1] = (PyObject *)task->task_context;
2844-
res = _PyObject_Vectorcall(add_cb, stack, 1, context_kwname);
2844+
res = PyObject_Vectorcall(add_cb, stack, 1, context_kwname);
28452845
Py_DECREF(add_cb);
28462846
Py_DECREF(wrapper);
28472847
if (res == NULL) {

Modules/_collectionsmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ deque_copy(PyObject *deque, PyObject *Py_UNUSED(ignored))
512512
return NULL;
513513
}
514514
if (old_deque->maxlen < 0)
515-
result = _PyObject_CallOneArg((PyObject *)(Py_TYPE(deque)), deque);
515+
result = PyObject_CallOneArg((PyObject *)(Py_TYPE(deque)), deque);
516516
else
517517
result = PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "Oi",
518518
deque, old_deque->maxlen, NULL);

Modules/_csv.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,10 @@ _call_dialect(PyObject *dialect_inst, PyObject *kwargs)
514514
{
515515
PyObject *type = (PyObject *)&Dialect_Type;
516516
if (dialect_inst) {
517-
return _PyObject_FastCallDict(type, &dialect_inst, 1, kwargs);
517+
return PyObject_VectorcallDict(type, &dialect_inst, 1, kwargs);
518518
}
519519
else {
520-
return _PyObject_FastCallDict(type, NULL, 0, kwargs);
520+
return PyObject_VectorcallDict(type, NULL, 0, kwargs);
521521
}
522522
}
523523

@@ -1240,7 +1240,7 @@ csv_writerow(WriterObj *self, PyObject *seq)
12401240
if (line == NULL) {
12411241
return NULL;
12421242
}
1243-
result = _PyObject_CallOneArg(self->write, line);
1243+
result = PyObject_CallOneArg(self->write, line);
12441244
Py_DECREF(line);
12451245
return result;
12461246
}

Modules/_ctypes/callproc.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker)
945945
if (!checker || !retval)
946946
return retval;
947947

948-
v = _PyObject_CallOneArg(checker, retval);
948+
v = PyObject_CallOneArg(checker, retval);
949949
if (v == NULL)
950950
_PyTraceback_Add("GetResult", "_ctypes/callproc.c", __LINE__-2);
951951
Py_DECREF(retval);
@@ -1138,7 +1138,7 @@ PyObject *_ctypes_callproc(PPROC pProc,
11381138
if (argtypes && argtype_count > i) {
11391139
PyObject *v;
11401140
converter = PyTuple_GET_ITEM(argtypes, i);
1141-
v = _PyObject_CallOneArg(converter, arg);
1141+
v = PyObject_CallOneArg(converter, arg);
11421142
if (v == NULL) {
11431143
_ctypes_extend_error(PyExc_ArgError, "argument %zd: ", i+1);
11441144
goto cleanup;
@@ -1835,15 +1835,15 @@ pointer(PyObject *self, PyObject *arg)
18351835

18361836
typ = PyDict_GetItemWithError(_ctypes_ptrtype_cache, (PyObject *)Py_TYPE(arg));
18371837
if (typ) {
1838-
return _PyObject_CallOneArg(typ, arg);
1838+
return PyObject_CallOneArg(typ, arg);
18391839
}
18401840
else if (PyErr_Occurred()) {
18411841
return NULL;
18421842
}
18431843
typ = POINTER(NULL, (PyObject *)Py_TYPE(arg));
18441844
if (typ == NULL)
18451845
return NULL;
1846-
result = _PyObject_CallOneArg(typ, arg);
1846+
result = PyObject_CallOneArg(typ, arg);
18471847
Py_DECREF(typ);
18481848
return result;
18491849
}

Modules/_elementtree.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -2671,7 +2671,7 @@ treebuilder_append_event(TreeBuilderObject *self, PyObject *action,
26712671
PyObject *event = PyTuple_Pack(2, action, node);
26722672
if (event == NULL)
26732673
return -1;
2674-
res = _PyObject_CallOneArg(self->events_append, event);
2674+
res = PyObject_CallOneArg(self->events_append, event);
26752675
Py_DECREF(event);
26762676
if (res == NULL)
26772677
return -1;
@@ -2837,7 +2837,7 @@ treebuilder_handle_comment(TreeBuilderObject* self, PyObject* text)
28372837
}
28382838

28392839
if (self->comment_factory) {
2840-
comment = _PyObject_CallOneArg(self->comment_factory, text);
2840+
comment = PyObject_CallOneArg(self->comment_factory, text);
28412841
if (!comment)
28422842
return NULL;
28432843

@@ -3179,7 +3179,7 @@ expat_set_error(enum XML_Error error_code, Py_ssize_t line, Py_ssize_t column,
31793179
if (errmsg == NULL)
31803180
return;
31813181

3182-
error = _PyObject_CallOneArg(st->parseerror_obj, errmsg);
3182+
error = PyObject_CallOneArg(st->parseerror_obj, errmsg);
31833183
Py_DECREF(errmsg);
31843184
if (!error)
31853185
return;
@@ -3242,7 +3242,7 @@ expat_default_handler(XMLParserObject* self, const XML_Char* data_in,
32423242
(TreeBuilderObject*) self->target, value
32433243
);
32443244
else if (self->handle_data)
3245-
res = _PyObject_CallOneArg(self->handle_data, value);
3245+
res = PyObject_CallOneArg(self->handle_data, value);
32463246
else
32473247
res = NULL;
32483248
Py_XDECREF(res);
@@ -3353,7 +3353,7 @@ expat_data_handler(XMLParserObject* self, const XML_Char* data_in,
33533353
/* shortcut */
33543354
res = treebuilder_handle_data((TreeBuilderObject*) self->target, data);
33553355
else if (self->handle_data)
3356-
res = _PyObject_CallOneArg(self->handle_data, data);
3356+
res = PyObject_CallOneArg(self->handle_data, data);
33573357
else
33583358
res = NULL;
33593359

@@ -3380,7 +3380,7 @@ expat_end_handler(XMLParserObject* self, const XML_Char* tag_in)
33803380
else if (self->handle_end) {
33813381
tag = makeuniversal(self, tag_in);
33823382
if (tag) {
3383-
res = _PyObject_CallOneArg(self->handle_end, tag);
3383+
res = PyObject_CallOneArg(self->handle_end, tag);
33843384
Py_DECREF(tag);
33853385
}
33863386
}
@@ -3467,7 +3467,7 @@ expat_end_ns_handler(XMLParserObject* self, const XML_Char* prefix_in)
34673467
if (!prefix)
34683468
return;
34693469

3470-
res = _PyObject_CallOneArg(self->handle_end_ns, prefix);
3470+
res = PyObject_CallOneArg(self->handle_end_ns, prefix);
34713471
Py_DECREF(prefix);
34723472
}
34733473

@@ -3499,7 +3499,7 @@ expat_comment_handler(XMLParserObject* self, const XML_Char* comment_in)
34993499
if (!comment)
35003500
return;
35013501

3502-
res = _PyObject_CallOneArg(self->handle_comment, comment);
3502+
res = PyObject_CallOneArg(self->handle_comment, comment);
35033503
Py_XDECREF(res);
35043504
Py_DECREF(comment);
35053505
}

Modules/_functoolsmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ partial_vectorcall(partialobject *pto, PyObject *const *args,
213213
static void
214214
partial_setvectorcall(partialobject *pto)
215215
{
216-
if (_PyVectorcall_Function(pto->fn) == NULL) {
216+
if (PyVectorcall_Function(pto->fn) == NULL) {
217217
/* Don't use vectorcall if the underlying function doesn't support it */
218218
pto->vectorcall = NULL;
219219
}
@@ -440,7 +440,7 @@ static PyTypeObject partial_type = {
440440
0, /* tp_as_buffer */
441441
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
442442
Py_TPFLAGS_BASETYPE |
443-
_Py_TPFLAGS_HAVE_VECTORCALL, /* tp_flags */
443+
Py_TPFLAGS_HAVE_VECTORCALL, /* tp_flags */
444444
partial_doc, /* tp_doc */
445445
(traverseproc)partial_traverse, /* tp_traverse */
446446
0, /* tp_clear */

0 commit comments

Comments
 (0)