bpo-37194: Add a new public PyObject_CallNoArgs() function (GH-13890)
Add a new public PyObject_CallNoArgs() function to the C API: call a
callable Python object without any arguments.
It is the most efficient way to call a callback without any argument.
On x86-64, for example, PyObject_CallFunctionObjArgs(func, NULL)
allocates 960 bytes on the stack per call, whereas
PyObject_CallNoArgs(func) only allocates 624 bytes per call.
It is excluded from stable ABI 3.8.
Replace private _PyObject_CallNoArg() with public
PyObject_CallNoArgs() in C extensions: _asyncio, _datetime,
_elementtree, _pickle, _tkinter and readline.
diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst
index ce0d059..aecd001 100644
--- a/Doc/c-api/object.rst
+++ b/Doc/c-api/object.rst
@@ -253,6 +253,16 @@
and ``0`` otherwise. This function always succeeds.
+.. c:function:: PyObject* PyObject_CallNoArgs(PyObject *callable)
+
+ Call a callable Python object *callable* without any arguments.
+
+ Returns the result of the call on success, or raise an exception and return
+ *NULL* on failure.
+
+ .. versionadded:: 3.9
+
+
.. c:function:: PyObject* PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
Call a callable Python object *callable*, with arguments given by the
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index ed55838..62b013f 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -102,6 +102,8 @@
Build and C API Changes
=======================
+* Add a new public :c:func:`PyObject_CallNoArgs` function to the C API:
+ call a callable Python object without any arguments.
Deprecated