Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-106023: Remove _PyObject_FastCall() function #106265

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,8 @@ Removed

Just remove the underscore prefix to update your code.
(Contributed by Victor Stinner in :gh:`106084`.)

* Remove private ``_PyObject_FastCall()`` function:
use ``PyObject_Vectorcall()`` which is available since Python 3.8
(:pep:`590`).
(Contributed by Victor Stinner in :gh:`106023`.)
6 changes: 0 additions & 6 deletions Include/cpython/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ PyAPI_FUNC(PyObject *) PyObject_VectorcallDict(
size_t nargsf,
PyObject *kwargs);

// Same as PyObject_Vectorcall(), except without keyword arguments
PyAPI_FUNC(PyObject *) _PyObject_FastCall(
PyObject *func,
PyObject *const *args,
Py_ssize_t nargs);

PyAPI_FUNC(PyObject *) PyObject_CallOneArg(PyObject *func, PyObject *arg);

static inline PyObject *
Expand Down
17 changes: 2 additions & 15 deletions Lib/test/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,19 +519,6 @@ def check_result(self, result, expected):
expected = (*expected[:-1], result[-1])
self.assertEqual(result, expected)

def test_fastcall(self):
# Test _PyObject_FastCall()

for func, args, expected in self.CALLS_POSARGS:
with self.subTest(func=func, args=args):
result = _testcapi.pyobject_fastcall(func, args)
self.check_result(result, expected)

if not args:
# args=NULL, nargs=0
result = _testcapi.pyobject_fastcall(func, None)
self.check_result(result, expected)

def test_vectorcall_dict(self):
# Test PyObject_VectorcallDict()

Expand Down Expand Up @@ -945,11 +932,11 @@ def py_recurse(n, m):

def c_recurse(n):
if n:
_testcapi.pyobject_fastcall(c_recurse, (n-1,))
_testcapi.pyobject_vectorcall(c_recurse, (n-1,), ())

def c_py_recurse(m):
if m:
_testcapi.pyobject_fastcall(py_recurse, (1000, m))
_testcapi.pyobject_vectorcall(py_recurse, (1000, m), ())

depth = sys.getrecursionlimit()
sys.setrecursionlimit(100_000)
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,13 +729,13 @@ def test_two_abs_args(self):

SAMPLE_WITH_C_CALL = """

from _testcapi import pyobject_fastcall
from _testcapi import pyobject_vectorcall

def foo(a, b, c):
bar(a, b, c)

def bar(a, b, c):
pyobject_fastcall(baz, (a, b, c))
pyobject_vectorcall(baz, (a, b, c), None)

def baz(*args):
id(42)
Expand All @@ -756,7 +756,7 @@ def test_pyup_command(self):
self.assertMultilineMatches(bt,
r'''^.*
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
#[0-9]+ <built-in method pyobject_fastcall of module object at remote 0x[0-9a-f]+>
#[0-9]+ <built-in method pyobject_vectorcall of module object at remote 0x[0-9a-f]+>
$''')

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove private ``_PyObject_FastCall()`` function: use ``PyObject_Vectorcall()``
which is available since Python 3.8 (:pep:`590`). Patch by Victor Stinner.
18 changes: 0 additions & 18 deletions Modules/_testcapi/vectorcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,6 @@ fastcall_args(PyObject *args, PyObject ***stack, Py_ssize_t *nargs)
}


static PyObject *
test_pyobject_fastcall(PyObject *self, PyObject *args)
{
PyObject *func, *func_args;
PyObject **stack;
Py_ssize_t nargs;

if (!PyArg_ParseTuple(args, "OO", &func, &func_args)) {
return NULL;
}

if (fastcall_args(func_args, &stack, &nargs) < 0) {
return NULL;
}
return _PyObject_FastCall(func, stack, nargs);
}

static PyObject *
test_pyobject_fastcalldict(PyObject *self, PyObject *args)
{
Expand Down Expand Up @@ -259,7 +242,6 @@ _testcapi_has_vectorcall_flag_impl(PyObject *module, PyTypeObject *type)
}

static PyMethodDef TestMethods[] = {
{"pyobject_fastcall", test_pyobject_fastcall, METH_VARARGS},
{"pyobject_fastcalldict", test_pyobject_fastcalldict, METH_VARARGS},
{"pyobject_vectorcall", test_pyobject_vectorcall, METH_VARARGS},
{"function_setvectorcall", function_setvectorcall, METH_O},
Expand Down
8 changes: 0 additions & 8 deletions Objects/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,6 @@ PyObject_Vectorcall(PyObject *callable, PyObject *const *args,
}


PyObject *
_PyObject_FastCall(PyObject *func, PyObject *const *args, Py_ssize_t nargs)
{
PyThreadState *tstate = _PyThreadState_GET();
return _PyObject_FastCallTstate(tstate, func, args, nargs);
}


PyObject *
_PyObject_Call(PyThreadState *tstate, PyObject *callable,
PyObject *args, PyObject *kwargs)
Expand Down