Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-105107: Remove PyCFunction_Call() function#105181

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 1 commit intopython:mainfromvstinner:remove_cfunc_call
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
1 change: 0 additions & 1 deletionDoc/data/stable_abi.dat
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

1 change: 1 addition & 0 deletionsDoc/whatsnew/3.13.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -373,6 +373,7 @@ Removed
:c:func:`PyTuple_New(0) <PyTuple_New>`.
* ``PyEval_CallFunction()``: use :c:func:`PyObject_CallFunction` instead.
* ``PyEval_CallMethod()``: use :c:func:`PyObject_CallMethod` instead.
* ``PyCFunction_Call()``: use :c:func:`PyObject_Call` instead.

(Contributed by Victor Stinner in :gh:`105107`.)

Expand Down
2 changes: 0 additions & 2 deletionsInclude/methodobject.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,8 +49,6 @@ PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);

Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);

struct PyMethodDef {
const char *ml_name; /* The name of the built-in function/method */
PyCFunction ml_meth; /* The C function that implements it */
Expand Down
20 changes: 20 additions & 0 deletionsLib/test/test_call.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -966,6 +966,7 @@ def c_py_recurse(m):
finally:
sys.setrecursionlimit(depth)


class TestFunctionWithManyArgs(unittest.TestCase):
def test_function_with_many_args(self):
for N in (10, 500, 1000):
Expand All@@ -977,5 +978,24 @@ def test_function_with_many_args(self):
self.assertEqual(l['f'](*range(N)), N//2)


@unittest.skipIf(_testcapi is None, 'need _testcapi')
class TestCAPI(unittest.TestCase):
def test_cfunction_call(self):
def func(*args, **kwargs):
return (args, kwargs)

# PyCFunction_Call() was removed in Python 3.13 API, but was kept in
# the stable ABI.
def PyCFunction_Call(func, *args, **kwargs):
if kwargs:
return _testcapi.pycfunction_call(func, args, kwargs)
else:
return _testcapi.pycfunction_call(func, args)

self.assertEqual(PyCFunction_Call(func), ((), {}))
self.assertEqual(PyCFunction_Call(func, 1, 2, 3), ((1, 2, 3), {}))
self.assertEqual(PyCFunction_Call(func, "arg", num=5), (("arg",), {'num': 5}))


if __name__ == "__main__":
unittest.main()
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,5 +5,6 @@ Remove functions deprecated in Python 3.9.
arguments must not be *NULL*) instead.
* ``PyEval_CallFunction()``: use :c:func:`PyObject_CallFunction` instead.
* ``PyEval_CallMethod()``: use :c:func:`PyObject_CallMethod` instead.
* ``PyCFunction_Call()``: use :c:func:`PyObject_Call` instead.

Patch by Victor Stinner.
1 change: 1 addition & 0 deletionsMisc/stable_abi.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -447,6 +447,7 @@
added = '3.2'
[function.PyCFunction_Call]
added = '3.2'
abi_only = true
[function.PyCFunction_GetFlags]
added = '3.2'
[function.PyCFunction_GetFunction]
Expand Down
14 changes: 14 additions & 0 deletionsModules/_testcapimodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2362,6 +2362,19 @@ meth_fastcall_keywords(PyObject* self, PyObject* const* args,
return Py_BuildValue("NNN", _null_to_none(self), pyargs, pykwargs);
}

static PyObject*
test_pycfunction_call(PyObject *module, PyObject *args)
{
// Function removed in the Python 3.13 API but was kept in the stable ABI.
extern PyObject* PyCFunction_Call(PyObject *callable, PyObject *args, PyObject *kwargs);

PyObject *func, *pos_args, *kwargs = NULL;
if (!PyArg_ParseTuple(args, "OO!|O!", &func, &PyTuple_Type, &pos_args, &PyDict_Type, &kwargs)) {
return NULL;
}
return PyCFunction_Call(func, pos_args, kwargs);
}

static PyObject*
pynumber_tobase(PyObject *module, PyObject *args)
{
Expand DownExpand Up@@ -3369,6 +3382,7 @@ static PyMethodDef TestMethods[] = {
{"meth_noargs", meth_noargs, METH_NOARGS},
{"meth_fastcall", _PyCFunction_CAST(meth_fastcall), METH_FASTCALL},
{"meth_fastcall_keywords", _PyCFunction_CAST(meth_fastcall_keywords), METH_FASTCALL|METH_KEYWORDS},
{"pycfunction_call", test_pycfunction_call, METH_VARARGS},
{"pynumber_tobase", pynumber_tobase, METH_VARARGS},
{"test_set_type_size", test_set_type_size, METH_NOARGS},
{"test_py_clear", test_py_clear, METH_NOARGS},
Expand Down
6 changes: 3 additions & 3 deletionsObjects/call.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -380,11 +380,11 @@ PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
}


PyObject *
/* Function removed in the Python 3.13 API but kept in the stable ABI. */
PyAPI_FUNC(PyObject *)
PyCFunction_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
{
PyThreadState *tstate = _PyThreadState_GET();
return _PyObject_Call(tstate, callable, args, kwargs);
return PyObject_Call(callable, args, kwargs);
}


Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp