GeezerVison is showing github.com — bpo-37194: Add a new public PyObject_CallNoArgs() function (GH-13890) · lisroach/cpython@ccfa9f2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Doc/c-api/object.rst +10Lines changed: 10 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -253,6 +253,16 @@ Object Protocol | 253 | 253 | and ``0`` otherwise. This function always succeeds. | 254 | 254 |
| 255 | 255 |
| | 256 | +.. c:function:: PyObject* PyObject_CallNoArgs(PyObject *callable) | | 257 | +
| | 258 | + Call a callable Python object *callable* without any arguments. | | 259 | +
| | 260 | + Returns the result of the call on success, or raise an exception and return | | 261 | + *NULL* on failure. | | 262 | +
| | 263 | + .. versionadded:: 3.9 | | 264 | +
| | 265 | +
| 256 | 266 | .. c:function:: PyObject* PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs) | 257 | 267 |
| 258 | 268 | Call a callable Python object *callable*, with arguments given by the | |
Collapse file Copy file name to clipboardExpand all lines: Doc/whatsnew/3.9.rst +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -102,6 +102,8 @@ Optimizations | 102 | 102 | Build and C API Changes | 103 | 103 | ======================= | 104 | 104 |
| | 105 | +* Add a new public :c:func:`PyObject_CallNoArgs` function to the C API: | | 106 | + call a callable Python object without any arguments. | 105 | 107 |
| 106 | 108 |
| 107 | 109 | Deprecated | |
Collapse file Copy file name to clipboardExpand all lines: Include/abstract.h +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -141,6 +141,12 @@ extern "C" { | 141 | 141 | #endif | 142 | 142 |
| 143 | 143 |
| | 144 | +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 | | 145 | +/* Call a callable Python object without any arguments */ | | 146 | +PyAPI_FUNC(PyObject *) PyObject_CallNoArgs(PyObject *func); | | 147 | +#endif | | 148 | + | | 149 | + | 144 | 150 | /* Call a callable Python object 'callable' with arguments given by the | 145 | 151 | tuple 'args' and keywords arguments given by the dictionary 'kwargs'. | 146 | 152 |
| |
Collapse file Copy file name to clipboardExpand all lines: Include/cpython/abstract.h +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -144,7 +144,9 @@ _PyObject_FastCall(PyObject *func, PyObject *const *args, Py_ssize_t nargs) | 144 | 144 | return _PyObject_Vectorcall(func, args, (size_t)nargs, NULL); | 145 | 145 | } | 146 | 146 |
| 147 | | -/* Call a callable without any arguments */ | | 147 | +/* Call a callable without any arguments | | 148 | + Private static inline function variant of public function | | 149 | + PyObject_CallNoArgs(). */ | 148 | 150 | static inline PyObject * | 149 | 151 | _PyObject_CallNoArg(PyObject *func) { | 150 | 152 | return _PyObject_Vectorcall(func, NULL, 0, NULL); | |
Collapse file Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +Add a new public :c:func:`PyObject_CallNoArgs` function to the C API: call a | | 2 | +callable Python object without any arguments. It is the most efficient way to | | 3 | +call a callback without any argument. On x86-64, for example, | | 4 | +``PyObject_CallFunctionObjArgs(func, NULL)`` allocates 960 bytes on the stack | | 5 | +per call, whereas ``PyObject_CallNoArgs(func)`` only allocates 624 bytes per | | 6 | +call. |
Collapse file Copy file name to clipboardExpand all lines: Modules/_asynciomodule.c +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -216,7 +216,7 @@ get_future_loop(PyObject *fut) | 216 | 216 | return NULL; | 217 | 217 | } | 218 | 218 | if (getloop != NULL) { | 219 | | - PyObject *res = _PyObject_CallNoArg(getloop); | | 219 | + PyObject *res = PyObject_CallNoArgs(getloop); | 220 | 220 | Py_DECREF(getloop); | 221 | 221 | return res; | 222 | 222 | } | @@ -328,7 +328,7 @@ get_event_loop(void) | 328 | 328 | return loop; | 329 | 329 | } | 330 | 330 |
| 331 | | - policy = _PyObject_CallNoArg(asyncio_get_event_loop_policy); | | 331 | + policy = PyObject_CallNoArgs(asyncio_get_event_loop_policy); | 332 | 332 | if (policy == NULL) { | 333 | 333 | return NULL; | 334 | 334 | } | @@ -510,7 +510,7 @@ future_init(FutureObj *fut, PyObject *loop) | 510 | 510 | method, which is called during the interpreter shutdown and the | 511 | 511 | traceback module is already unloaded. | 512 | 512 | */ | 513 | | - fut->fut_source_tb = _PyObject_CallNoArg(traceback_extract_stack); | | 513 | + fut->fut_source_tb = PyObject_CallNoArgs(traceback_extract_stack); | 514 | 514 | if (fut->fut_source_tb == NULL) { | 515 | 515 | return -1; | 516 | 516 | } | @@ -553,7 +553,7 @@ future_set_exception(FutureObj *fut, PyObject *exc) | 553 | 553 | } | 554 | 554 |
| 555 | 555 | if (PyExceptionClass_Check(exc)) { | 556 | | - exc_val = _PyObject_CallNoArg(exc); | | 556 | + exc_val = PyObject_CallNoArgs(exc); | 557 | 557 | if (exc_val == NULL) { | 558 | 558 | return NULL; | 559 | 559 | } | @@ -2593,7 +2593,7 @@ task_step_impl(TaskObj *task, PyObject *exc) | 2593 | 2593 |
| 2594 | 2594 | if (!exc) { | 2595 | 2595 | /* exc was not a CancelledError */ | 2596 | | - exc = _PyObject_CallNoArg(asyncio_CancelledError); | | 2596 | + exc = PyObject_CallNoArgs(asyncio_CancelledError); | 2597 | 2597 | if (!exc) { | 2598 | 2598 | goto fail; | 2599 | 2599 | } | @@ -3308,7 +3308,7 @@ module_init(void) | 3308 | 3308 | PyObject *weak_set; | 3309 | 3309 | WITH_MOD("weakref") | 3310 | 3310 | GET_MOD_ATTR(weak_set, "WeakSet"); | 3311 | | - all_tasks = _PyObject_CallNoArg(weak_set); | | 3311 | + all_tasks = PyObject_CallNoArgs(weak_set); | 3312 | 3312 | Py_CLEAR(weak_set); | 3313 | 3313 | if (all_tasks == NULL) { | 3314 | 3314 | goto fail; | |
Collapse file Copy file name to clipboardExpand all lines: Modules/_datetimemodule.c +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1528,8 +1528,8 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, | 1528 | 1528 | ntoappend = 1; | 1529 | 1529 | } | 1530 | 1530 | else if ((ch = *pin++) == '\0') { | 1531 | | - /* Null byte follows %, copy only '%'. | 1532 | | - * | | 1531 | + /* Null byte follows %, copy only '%'. | | 1532 | + * | 1533 | 1533 | * Back the pin up one char so that we catch the null check | 1534 | 1534 | * the next time through the loop.*/ | 1535 | 1535 | pin--; | @@ -1619,7 +1619,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, | 1619 | 1619 | usednew += ntoappend; | 1620 | 1620 | assert(usednew <= totalnew); | 1621 | 1621 | } /* end while() */ | 1622 | | - | | 1622 | + | 1623 | 1623 | if (_PyBytes_Resize(&newfmt, usednew) < 0) | 1624 | 1624 | goto Done; | 1625 | 1625 | { | @@ -3607,7 +3607,7 @@ tzinfo_reduce(PyObject *self, PyObject *Py_UNUSED(ignored)) | 3607 | 3607 |
| 3608 | 3608 | getinitargs = _PyObject_GetAttrId(self, &PyId___getinitargs__); | 3609 | 3609 | if (getinitargs != NULL) { | 3610 | | - args = _PyObject_CallNoArg(getinitargs); | | 3610 | + args = PyObject_CallNoArgs(getinitargs); | 3611 | 3611 | Py_DECREF(getinitargs); | 3612 | 3612 | if (args == NULL) { | 3613 | 3613 | return NULL; | @@ -3624,7 +3624,7 @@ tzinfo_reduce(PyObject *self, PyObject *Py_UNUSED(ignored)) | 3624 | 3624 |
| 3625 | 3625 | getstate = _PyObject_GetAttrId(self, &PyId___getstate__); | 3626 | 3626 | if (getstate != NULL) { | 3627 | | - state = _PyObject_CallNoArg(getstate); | | 3627 | + state = PyObject_CallNoArgs(getstate); | 3628 | 3628 | Py_DECREF(getstate); | 3629 | 3629 | if (state == NULL) { | 3630 | 3630 | Py_DECREF(args); | |
Collapse file Copy file name to clipboardExpand all lines: Modules/_elementtree.c +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -3892,7 +3892,7 @@ _elementtree_XMLParser_close_impl(XMLParserObject *self) | 3892 | 3892 | } | 3893 | 3893 | else if (self->handle_close) { | 3894 | 3894 | Py_DECREF(res); | 3895 | | - return _PyObject_CallNoArg(self->handle_close); | | 3895 | + return PyObject_CallNoArgs(self->handle_close); | 3896 | 3896 | } | 3897 | 3897 | else { | 3898 | 3898 | return res; | |
Collapse file Copy file name to clipboardExpand all lines: Modules/_pickle.c +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1274,7 +1274,7 @@ _Unpickler_ReadFromFile(UnpicklerObject *self, Py_ssize_t n) | 1274 | 1274 | return -1; | 1275 | 1275 |
| 1276 | 1276 | if (n == READ_WHOLE_LINE) { | 1277 | | - data = _PyObject_CallNoArg(self->readline); | | 1277 | + data = PyObject_CallNoArgs(self->readline); | 1278 | 1278 | } | 1279 | 1279 | else { | 1280 | 1280 | PyObject *len; | @@ -4411,7 +4411,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save) | 4411 | 4411 | /* Check for a __reduce__ method. */ | 4412 | 4412 | reduce_func = _PyObject_GetAttrId(obj, &PyId___reduce__); | 4413 | 4413 | if (reduce_func != NULL) { | 4414 | | - reduce_value = _PyObject_CallNoArg(reduce_func); | | 4414 | + reduce_value = PyObject_CallNoArgs(reduce_func); | 4415 | 4415 | } | 4416 | 4416 | else { | 4417 | 4417 | PyErr_Format(st->PicklingError, | |
Collapse file Copy file name to clipboardExpand all lines: Modules/_tkinter.c +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2768,7 +2768,7 @@ TimerHandler(ClientData clientData) | 2768 | 2768 |
| 2769 | 2769 | ENTER_PYTHON | 2770 | 2770 |
| 2771 | | - res = _PyObject_CallNoArg(func); | | 2771 | + res = PyObject_CallNoArgs(func); | 2772 | 2772 | Py_DECREF(func); | 2773 | 2773 | Py_DECREF(v); /* See Tktt_New() */ | 2774 | 2774 |
| |
|