mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-106023: Remove _PyObject_FastCall() function (#106265)
This commit is contained in:
parent
0b51463862
commit
2efdd2a14e
7 changed files with 13 additions and 51 deletions
|
@ -597,3 +597,8 @@ Removed
|
||||||
|
|
||||||
Just remove the underscore prefix to update your code.
|
Just remove the underscore prefix to update your code.
|
||||||
(Contributed by Victor Stinner in :gh:`106084`.)
|
(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`.)
|
||||||
|
|
|
@ -24,12 +24,6 @@ PyAPI_FUNC(PyObject *) PyObject_VectorcallDict(
|
||||||
size_t nargsf,
|
size_t nargsf,
|
||||||
PyObject *kwargs);
|
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);
|
PyAPI_FUNC(PyObject *) PyObject_CallOneArg(PyObject *func, PyObject *arg);
|
||||||
|
|
||||||
static inline PyObject *
|
static inline PyObject *
|
||||||
|
|
|
@ -519,19 +519,6 @@ class FastCallTests(unittest.TestCase):
|
||||||
expected = (*expected[:-1], result[-1])
|
expected = (*expected[:-1], result[-1])
|
||||||
self.assertEqual(result, expected)
|
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):
|
def test_vectorcall_dict(self):
|
||||||
# Test PyObject_VectorcallDict()
|
# Test PyObject_VectorcallDict()
|
||||||
|
|
||||||
|
@ -945,11 +932,11 @@ class TestRecursion(unittest.TestCase):
|
||||||
|
|
||||||
def c_recurse(n):
|
def c_recurse(n):
|
||||||
if n:
|
if n:
|
||||||
_testcapi.pyobject_fastcall(c_recurse, (n-1,))
|
_testcapi.pyobject_vectorcall(c_recurse, (n-1,), ())
|
||||||
|
|
||||||
def c_py_recurse(m):
|
def c_py_recurse(m):
|
||||||
if m:
|
if m:
|
||||||
_testcapi.pyobject_fastcall(py_recurse, (1000, m))
|
_testcapi.pyobject_vectorcall(py_recurse, (1000, m), ())
|
||||||
|
|
||||||
depth = sys.getrecursionlimit()
|
depth = sys.getrecursionlimit()
|
||||||
sys.setrecursionlimit(100_000)
|
sys.setrecursionlimit(100_000)
|
||||||
|
|
|
@ -729,13 +729,13 @@ class PyListTests(DebuggerTests):
|
||||||
|
|
||||||
SAMPLE_WITH_C_CALL = """
|
SAMPLE_WITH_C_CALL = """
|
||||||
|
|
||||||
from _testcapi import pyobject_fastcall
|
from _testcapi import pyobject_vectorcall
|
||||||
|
|
||||||
def foo(a, b, c):
|
def foo(a, b, c):
|
||||||
bar(a, b, c)
|
bar(a, b, c)
|
||||||
|
|
||||||
def 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):
|
def baz(*args):
|
||||||
id(42)
|
id(42)
|
||||||
|
@ -756,7 +756,7 @@ class StackNavigationTests(DebuggerTests):
|
||||||
self.assertMultilineMatches(bt,
|
self.assertMultilineMatches(bt,
|
||||||
r'''^.*
|
r'''^.*
|
||||||
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
|
#[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")
|
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
|
||||||
|
@ -785,7 +785,7 @@ $''')
|
||||||
self.assertMultilineMatches(bt,
|
self.assertMultilineMatches(bt,
|
||||||
r'''^.*
|
r'''^.*
|
||||||
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
|
#[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\)\)
|
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
|
||||||
$''')
|
$''')
|
||||||
|
|
||||||
|
|
|
@ -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.
|
|
@ -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 *
|
static PyObject *
|
||||||
test_pyobject_fastcalldict(PyObject *self, PyObject *args)
|
test_pyobject_fastcalldict(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
@ -259,7 +242,6 @@ _testcapi_has_vectorcall_flag_impl(PyObject *module, PyTypeObject *type)
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef TestMethods[] = {
|
static PyMethodDef TestMethods[] = {
|
||||||
{"pyobject_fastcall", test_pyobject_fastcall, METH_VARARGS},
|
|
||||||
{"pyobject_fastcalldict", test_pyobject_fastcalldict, METH_VARARGS},
|
{"pyobject_fastcalldict", test_pyobject_fastcalldict, METH_VARARGS},
|
||||||
{"pyobject_vectorcall", test_pyobject_vectorcall, METH_VARARGS},
|
{"pyobject_vectorcall", test_pyobject_vectorcall, METH_VARARGS},
|
||||||
{"function_setvectorcall", function_setvectorcall, METH_O},
|
{"function_setvectorcall", function_setvectorcall, METH_O},
|
||||||
|
|
|
@ -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 *
|
||||||
_PyObject_Call(PyThreadState *tstate, PyObject *callable,
|
_PyObject_Call(PyThreadState *tstate, PyObject *callable,
|
||||||
PyObject *args, PyObject *kwargs)
|
PyObject *args, PyObject *kwargs)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue