Skip to content

Commit 2efdd2a

Browse files
authored
gh-106023: Remove _PyObject_FastCall() function (#106265)
1 parent 0b51463 commit 2efdd2a

File tree

7 files changed

+13
-51
lines changed

7 files changed

+13
-51
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,8 @@ Removed
597597

598598
Just remove the underscore prefix to update your code.
599599
(Contributed by Victor Stinner in :gh:`106084`.)
600+
601+
* Remove private ``_PyObject_FastCall()`` function:
602+
use ``PyObject_Vectorcall()`` which is available since Python 3.8
603+
(:pep:`590`).
604+
(Contributed by Victor Stinner in :gh:`106023`.)

Include/cpython/abstract.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ PyAPI_FUNC(PyObject *) PyObject_VectorcallDict(
2424
size_t nargsf,
2525
PyObject *kwargs);
2626

27-
// Same as PyObject_Vectorcall(), except without keyword arguments
28-
PyAPI_FUNC(PyObject *) _PyObject_FastCall(
29-
PyObject *func,
30-
PyObject *const *args,
31-
Py_ssize_t nargs);
32-
3327
PyAPI_FUNC(PyObject *) PyObject_CallOneArg(PyObject *func, PyObject *arg);
3428

3529
static inline PyObject *

Lib/test/test_call.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -519,19 +519,6 @@ def check_result(self, result, expected):
519519
expected = (*expected[:-1], result[-1])
520520
self.assertEqual(result, expected)
521521

522-
def test_fastcall(self):
523-
# Test _PyObject_FastCall()
524-
525-
for func, args, expected in self.CALLS_POSARGS:
526-
with self.subTest(func=func, args=args):
527-
result = _testcapi.pyobject_fastcall(func, args)
528-
self.check_result(result, expected)
529-
530-
if not args:
531-
# args=NULL, nargs=0
532-
result = _testcapi.pyobject_fastcall(func, None)
533-
self.check_result(result, expected)
534-
535522
def test_vectorcall_dict(self):
536523
# Test PyObject_VectorcallDict()
537524

@@ -945,11 +932,11 @@ def py_recurse(n, m):
945932

946933
def c_recurse(n):
947934
if n:
948-
_testcapi.pyobject_fastcall(c_recurse, (n-1,))
935+
_testcapi.pyobject_vectorcall(c_recurse, (n-1,), ())
949936

950937
def c_py_recurse(m):
951938
if m:
952-
_testcapi.pyobject_fastcall(py_recurse, (1000, m))
939+
_testcapi.pyobject_vectorcall(py_recurse, (1000, m), ())
953940

954941
depth = sys.getrecursionlimit()
955942
sys.setrecursionlimit(100_000)

Lib/test/test_gdb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,13 +729,13 @@ def test_two_abs_args(self):
729729

730730
SAMPLE_WITH_C_CALL = """
731731
732-
from _testcapi import pyobject_fastcall
732+
from _testcapi import pyobject_vectorcall
733733
734734
def foo(a, b, c):
735735
bar(a, b, c)
736736
737737
def bar(a, b, c):
738-
pyobject_fastcall(baz, (a, b, c))
738+
pyobject_vectorcall(baz, (a, b, c), None)
739739
740740
def baz(*args):
741741
id(42)
@@ -756,7 +756,7 @@ def test_pyup_command(self):
756756
self.assertMultilineMatches(bt,
757757
r'''^.*
758758
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
759-
#[0-9]+ <built-in method pyobject_fastcall of module object at remote 0x[0-9a-f]+>
759+
#[0-9]+ <built-in method pyobject_vectorcall of module object at remote 0x[0-9a-f]+>
760760
$''')
761761

762762
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
@@ -785,7 +785,7 @@ def test_up_then_down(self):
785785
self.assertMultilineMatches(bt,
786786
r'''^.*
787787
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
788-
#[0-9]+ <built-in method pyobject_fastcall of module object at remote 0x[0-9a-f]+>
788+
#[0-9]+ <built-in method pyobject_vectorcall of module object at remote 0x[0-9a-f]+>
789789
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
790790
$''')
791791

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove private ``_PyObject_FastCall()`` function: use ``PyObject_Vectorcall()``
2+
which is available since Python 3.8 (:pep:`590`). Patch by Victor Stinner.

Modules/_testcapi/vectorcall.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,6 @@ fastcall_args(PyObject *args, PyObject ***stack, Py_ssize_t *nargs)
2626
}
2727

2828

29-
static PyObject *
30-
test_pyobject_fastcall(PyObject *self, PyObject *args)
31-
{
32-
PyObject *func, *func_args;
33-
PyObject **stack;
34-
Py_ssize_t nargs;
35-
36-
if (!PyArg_ParseTuple(args, "OO", &func, &func_args)) {
37-
return NULL;
38-
}
39-
40-
if (fastcall_args(func_args, &stack, &nargs) < 0) {
41-
return NULL;
42-
}
43-
return _PyObject_FastCall(func, stack, nargs);
44-
}
45-
4629
static PyObject *
4730
test_pyobject_fastcalldict(PyObject *self, PyObject *args)
4831
{
@@ -259,7 +242,6 @@ _testcapi_has_vectorcall_flag_impl(PyObject *module, PyTypeObject *type)
259242
}
260243

261244
static PyMethodDef TestMethods[] = {
262-
{"pyobject_fastcall", test_pyobject_fastcall, METH_VARARGS},
263245
{"pyobject_fastcalldict", test_pyobject_fastcalldict, METH_VARARGS},
264246
{"pyobject_vectorcall", test_pyobject_vectorcall, METH_VARARGS},
265247
{"function_setvectorcall", function_setvectorcall, METH_O},

Objects/call.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,6 @@ PyObject_Vectorcall(PyObject *callable, PyObject *const *args,
327327
}
328328

329329

330-
PyObject *
331-
_PyObject_FastCall(PyObject *func, PyObject *const *args, Py_ssize_t nargs)
332-
{
333-
PyThreadState *tstate = _PyThreadState_GET();
334-
return _PyObject_FastCallTstate(tstate, func, args, nargs);
335-
}
336-
337-
338330
PyObject *
339331
_PyObject_Call(PyThreadState *tstate, PyObject *callable,
340332
PyObject *args, PyObject *kwargs)

0 commit comments

Comments
 (0)