Skip to content

Commit d943d19

Browse files
authored
bpo-45439: Move _PyObject_CallNoArgs() to pycore_call.h (GH-28895)
* Move _PyObject_CallNoArgs() to pycore_call.h (internal C API). * _ssl, _sqlite and _testcapi extensions now call the public PyObject_CallNoArgs() function, rather than _PyObject_CallNoArgs(). * _lsprof extension is now built with Py_BUILD_CORE_MODULE macro defined to get access to internal _PyObject_CallNoArgs().
1 parent be21706 commit d943d19

38 files changed

+89
-64
lines changed

Include/cpython/abstract.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,6 @@ _PyObject_FastCall(PyObject *func, PyObject *const *args, Py_ssize_t nargs)
160160
return _PyObject_FastCallTstate(tstate, func, args, nargs);
161161
}
162162

163-
/* Call a callable without any arguments
164-
Private static inline function variant of public function
165-
PyObject_CallNoArgs(). */
166-
static inline PyObject *
167-
_PyObject_CallNoArgs(PyObject *func) {
168-
PyThreadState *tstate = PyThreadState_Get();
169-
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
170-
}
171-
172163
static inline PyObject *
173164
PyObject_CallOneArg(PyObject *func, PyObject *arg)
174165
{

Include/internal/pycore_call.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ _PyObject_CallNoArgsTstate(PyThreadState *tstate, PyObject *func) {
3333
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
3434
}
3535

36+
// Private static inline function variant of public PyObject_CallNoArgs()
37+
static inline PyObject *
38+
_PyObject_CallNoArgs(PyObject *func) {
39+
PyThreadState *tstate = PyThreadState_Get();
40+
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
41+
}
42+
3643
#ifdef __cplusplus
3744
}
3845
#endif

Modules/_collectionsmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Python.h"
2+
#include "pycore_call.h" // _PyObject_CallNoArgs()
23
#include "pycore_long.h" // _PyLong_GetZero()
34
#include "structmember.h" // PyMemberDef
45

Modules/_ctypes/_ctypes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ bytes(cdata)
102102
#define PY_SSIZE_T_CLEAN
103103

104104
#include "Python.h"
105+
#include "pycore_call.h" // _PyObject_CallNoArgs()
105106
#include "structmember.h" // PyMemberDef
106107

107108
#include <ffi.h>

Modules/_ctypes/callbacks.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Python.h"
2+
#include "pycore_call.h" // _PyObject_CallNoArgs()
23
#include "frameobject.h"
34

45
#include <stdbool.h>

Modules/_ctypes/cfield.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Python.h"
22
#include "pycore_bitutils.h" // _Py_bswap32()
3+
#include "pycore_call.h" // _PyObject_CallNoArgs()
34

45
#include <ffi.h>
56
#ifdef MS_WIN32

Modules/_ctypes/stgdict.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Python.h"
2+
#include "pycore_call.h" // _PyObject_CallNoArgs()
23
#include <ffi.h>
34
#ifdef MS_WIN32
45
#include <windows.h>

Modules/_functoolsmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Python.h"
2+
#include "pycore_call.h" // _PyObject_CallNoArgs()
23
#include "pycore_long.h" // _PyLong_GetZero()
34
#include "pycore_moduleobject.h" // _PyModule_GetState()
45
#include "pycore_object.h" // _PyObject_GC_TRACK

Modules/_io/bufferedio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#define PY_SSIZE_T_CLEAN
1111
#include "Python.h"
12+
#include "pycore_call.h" // _PyObject_CallNoArgs()
1213
#include "pycore_object.h"
1314
#include "structmember.h" // PyMemberDef
1415
#include "_iomodule.h"

Modules/_lsprof.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Python.h"
2+
#include "pycore_call.h" // _PyObject_CallNoArgs()
23
#include "rotatingtree.h"
34

45
/************************************************************/

Modules/_sqlite/connection.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ step_callback(sqlite3_context *context, int argc, sqlite3_value **params)
710710
if (*aggregate_instance == NULL) {
711711
callback_context *ctx = (callback_context *)sqlite3_user_data(context);
712712
assert(ctx != NULL);
713-
*aggregate_instance = _PyObject_CallNoArgs(ctx->callable);
713+
*aggregate_instance = PyObject_CallNoArgs(ctx->callable);
714714
if (!*aggregate_instance) {
715715
set_sqlite_error(context,
716716
"user-defined aggregate's '__init__' method raised error");
@@ -1008,7 +1008,7 @@ progress_callback(void *ctx)
10081008

10091009
assert(ctx != NULL);
10101010
PyObject *callable = ((callback_context *)ctx)->callable;
1011-
ret = _PyObject_CallNoArgs(callable);
1011+
ret = PyObject_CallNoArgs(callable);
10121012
if (!ret) {
10131013
/* abort query if error occurred */
10141014
rc = -1;

Modules/_ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3773,7 +3773,7 @@ _password_callback(char *buf, int size, int rwflag, void *userdata)
37733773
}
37743774

37753775
if (pw_info->callable) {
3776-
fn_ret = _PyObject_CallNoArgs(pw_info->callable);
3776+
fn_ret = PyObject_CallNoArgs(pw_info->callable);
37773777
if (!fn_ret) {
37783778
/* TODO: It would be nice to move _ctypes_add_traceback() into the
37793779
core python API, so we could use it to add a frame here */

Modules/_testcapimodule.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,7 +2866,7 @@ _make_call(void *callable)
28662866
PyObject *rc;
28672867
int success;
28682868
PyGILState_STATE s = PyGILState_Ensure();
2869-
rc = _PyObject_CallNoArgs((PyObject *)callable);
2869+
rc = PyObject_CallNoArgs((PyObject *)callable);
28702870
success = (rc != NULL);
28712871
Py_XDECREF(rc);
28722872
PyGILState_Release(s);
@@ -2937,7 +2937,7 @@ static int _pending_callback(void *arg)
29372937
{
29382938
/* we assume the argument is callable object to which we own a reference */
29392939
PyObject *callable = (PyObject *)arg;
2940-
PyObject *r = _PyObject_CallNoArgs(callable);
2940+
PyObject *r = PyObject_CallNoArgs(callable);
29412941
Py_DECREF(callable);
29422942
Py_XDECREF(r);
29432943
return r != NULL ? 0 : -1;
@@ -3729,7 +3729,7 @@ slot_tp_del(PyObject *self)
37293729
/* Execute __del__ method, if any. */
37303730
del = _PyObject_LookupSpecial(self, &PyId___tp_del__);
37313731
if (del != NULL) {
3732-
res = _PyObject_CallNoArgs(del);
3732+
res = PyObject_CallNoArgs(del);
37333733
if (res == NULL)
37343734
PyErr_WriteUnraisable(del);
37353735
else
@@ -4358,7 +4358,7 @@ temporary_c_thread(void *data)
43584358
/* Allocate a Python thread state for this thread */
43594359
state = PyGILState_Ensure();
43604360

4361-
res = _PyObject_CallNoArgs(test_c_thread->callback);
4361+
res = PyObject_CallNoArgs(test_c_thread->callback);
43624362
Py_CLEAR(test_c_thread->callback);
43634363

43644364
if (res == NULL) {
@@ -4893,7 +4893,7 @@ check_pyobject_freed_is_freed(PyObject *self, PyObject *Py_UNUSED(args))
48934893
#ifdef _Py_ADDRESS_SANITIZER
48944894
Py_RETURN_NONE;
48954895
#else
4896-
PyObject *op = _PyObject_CallNoArgs((PyObject *)&PyBaseObject_Type);
4896+
PyObject *op = PyObject_CallNoArgs((PyObject *)&PyBaseObject_Type);
48974897
if (op == NULL) {
48984898
return NULL;
48994899
}
@@ -5271,7 +5271,7 @@ bad_get(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
52715271
return NULL;
52725272
}
52735273

5274-
PyObject *res = _PyObject_CallNoArgs(cls);
5274+
PyObject *res = PyObject_CallNoArgs(cls);
52755275
if (res == NULL) {
52765276
return NULL;
52775277
}

Modules/itertoolsmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
2-
31
#define PY_SSIZE_T_CLEAN
42
#include "Python.h"
3+
#include "pycore_call.h" // _PyObject_CallNoArgs()
54
#include "pycore_long.h" // _PyLong_GetZero()
65
#include "pycore_object.h" // _PyObject_GC_TRACK()
76
#include "pycore_tuple.h" // _PyTuple_ITEMS()

Modules/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* Python interpreter main program */
22

33
#include "Python.h"
4+
#include "pycore_call.h" // _PyObject_CallNoArgs()
45
#include "pycore_initconfig.h" // _PyArgv
56
#include "pycore_interp.h" // _PyInterpreterState.sysdict
67
#include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0()

Modules/mathmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ raised for division by zero and mod by zero.
5454

5555
#include "Python.h"
5656
#include "pycore_bitutils.h" // _Py_bit_length()
57-
#include "pycore_dtoa.h"
57+
#include "pycore_call.h" // _PyObject_CallNoArgs()
58+
#include "pycore_dtoa.h" // _Py_dg_infinity()
5859
#include "pycore_long.h" // _PyLong_GetZero()
5960
#include "_math.h"
6061

Modules/posixmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#define PY_SSIZE_T_CLEAN
1111

1212
#include "Python.h"
13-
#include "pycore_fileutils.h"
13+
#include "pycore_call.h" // _PyObject_CallNoArgs()
14+
#include "pycore_fileutils.h" // _Py_closerange()
1415
#include "pycore_moduleobject.h" // _PyModule_GetState()
1516
#ifdef MS_WINDOWS
1617
/* include <windows.h> early to avoid conflict with pycore_condvar.h:

Modules/signalmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "pycore_atomic.h" // _Py_atomic_int
88
#include "pycore_call.h" // _PyObject_Call()
99
#include "pycore_ceval.h" // _PyEval_SignalReceived()
10-
#include "pycore_frame.h"
10+
#include "pycore_frame.h" // InterpreterFrame
1111
#include "pycore_moduleobject.h" // _PyModule_GetState()
1212
#include "pycore_pyerrors.h" // _PyErr_SetString()
1313
#include "pycore_pylifecycle.h" // NSIG

Objects/abstract.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "Python.h"
44
#include "pycore_abstract.h" // _PyIndex_Check()
5+
#include "pycore_call.h" // _PyObject_CallNoArgs()
56
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
67
#include "pycore_object.h" // _Py_CheckSlotResult()
78
#include "pycore_pyerrors.h" // _PyErr_Occurred()

Objects/bytesobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Python.h"
66
#include "pycore_abstract.h" // _PyIndex_Check()
77
#include "pycore_bytes_methods.h" // _Py_bytes_startswith()
8+
#include "pycore_call.h" // _PyObject_CallNoArgs()
89
#include "pycore_format.h" // F_LJUST
910
#include "pycore_initconfig.h" // _PyStatus_OK()
1011
#include "pycore_object.h" // _PyObject_GC_TRACK

Objects/complexobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/* Submitted by Jim Hugunin */
77

88
#include "Python.h"
9+
#include "pycore_call.h" // _PyObject_CallNoArgs()
910
#include "pycore_long.h" // _PyLong_GetZero()
1011
#include "pycore_object.h" // _PyObject_Init()
1112
#include "pycore_pymath.h" // _Py_ADJUST_ERANGE2()

Objects/dictobject.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,14 @@ As a consequence of this, split keys have a maximum size of 16.
112112
#define PyDict_MINSIZE 8
113113

114114
#include "Python.h"
115-
#include "pycore_bitutils.h" // _Py_bit_length
116-
#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
117-
#include "pycore_object.h" // _PyObject_GC_TRACK()
118-
#include "pycore_pyerrors.h" // _PyErr_Fetch()
119-
#include "pycore_pystate.h" // _PyThreadState_GET()
120-
#include "pycore_dict.h"
121-
#include "stringlib/eq.h" // unicode_eq()
115+
#include "pycore_bitutils.h" // _Py_bit_length
116+
#include "pycore_call.h" // _PyObject_CallNoArgs()
117+
#include "pycore_dict.h" // PyDictKeysObject
118+
#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
119+
#include "pycore_object.h" // _PyObject_GC_TRACK()
120+
#include "pycore_pyerrors.h" // _PyErr_Fetch()
121+
#include "pycore_pystate.h" // _PyThreadState_GET()
122+
#include "stringlib/eq.h" // unicode_eq()
122123

123124
/*[clinic input]
124125
class dict "PyDictObject *" "&PyDict_Type"

Objects/enumobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* enumerate object */
22

33
#include "Python.h"
4+
#include "pycore_call.h" // _PyObject_CallNoArgs()
45
#include "pycore_long.h" // _PyLong_GetOne()
56
#include "pycore_object.h" // _PyObject_GC_TRACK()
67

Objects/fileobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
#define PY_SSIZE_T_CLEAN
44
#include "Python.h"
5-
#include "pycore_runtime.h" // _PyRuntime
5+
#include "pycore_call.h" // _PyObject_CallNoArgs()
6+
#include "pycore_runtime.h" // _PyRuntime
67

78
#if defined(HAVE_GETC_UNLOCKED) && !defined(_Py_MEMORY_SANITIZER)
89
/* clang MemorySanitizer doesn't yet understand getc_unlocked. */

Objects/genobject.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/* Generator object implementation */
22

33
#include "Python.h"
4+
#include "pycore_call.h" // _PyObject_CallNoArgs()
45
#include "pycore_ceval.h" // _PyEval_EvalFrame()
5-
#include "pycore_object.h"
6+
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
67
#include "pycore_pyerrors.h" // _PyErr_ClearExcState()
78
#include "pycore_pystate.h" // _PyThreadState_GET()
8-
#include "frameobject.h"
9-
#include "pycore_frame.h"
9+
#include "pycore_frame.h" // InterpreterFrame
10+
#include "frameobject.h" // PyFrameObject
1011
#include "structmember.h" // PyMemberDef
11-
#include "opcode.h"
12+
#include "opcode.h" // YIELD_FROM
1213

1314
static PyObject *gen_close(PyGenObject *, PyObject *);
1415
static PyObject *async_gen_asend_new(PyAsyncGenObject *, PyObject *);

Objects/iterobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* Iterator objects */
22

33
#include "Python.h"
4-
#include "pycore_object.h"
4+
#include "pycore_call.h" // _PyObject_CallNoArgs()
5+
#include "pycore_object.h" // _PyObject_GC_TRACK()
56

67
typedef struct {
78
PyObject_HEAD

Objects/moduleobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Module object implementation */
33

44
#include "Python.h"
5+
#include "pycore_call.h" // _PyObject_CallNoArgs()
56
#include "pycore_interp.h" // PyInterpreterState.importlib
67
#include "pycore_pystate.h" // _PyInterpreterState_GET()
78
#include "pycore_moduleobject.h" // _PyModule_GetDef()

Objects/object.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
/* Generic object operations; and implementation of None */
33

44
#include "Python.h"
5+
#include "pycore_call.h" // _PyObject_CallNoArgs()
56
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
67
#include "pycore_context.h"
7-
#include "pycore_initconfig.h"
8-
#include "pycore_object.h"
9-
#include "pycore_pyerrors.h"
10-
#include "pycore_pylifecycle.h"
8+
#include "pycore_initconfig.h" // _PyStatus_EXCEPTION()
9+
#include "pycore_object.h" // _PyType_CheckConsistency()
10+
#include "pycore_pyerrors.h" // _PyErr_Occurred()
11+
#include "pycore_pylifecycle.h" // _PyTypes_InitSlotDefs()
1112
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
1213
#include "pycore_pystate.h" // _PyThreadState_GET()
1314
#include "pycore_symtable.h" // PySTEntry_Type
1415
#include "pycore_unionobject.h" // _PyUnion_Type
15-
#include "frameobject.h"
16-
#include "interpreteridobject.h"
16+
#include "frameobject.h" // PyFrame_Type
17+
#include "interpreteridobject.h" // _PyInterpreterID_Type
1718

1819
#ifdef Py_LIMITED_API
1920
// Prevent recursive call _Py_IncRef() <=> Py_INCREF()

Objects/odictobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,10 @@ Potential Optimizations
465465
*/
466466

467467
#include "Python.h"
468-
#include "pycore_object.h"
468+
#include "pycore_call.h" // _PyObject_CallNoArgs()
469+
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
470+
#include "pycore_dict.h" // _Py_dict_lookup()
469471
#include <stddef.h> // offsetof()
470-
#include "pycore_dict.h"
471-
#include <stddef.h>
472472

473473
#include "clinic/odictobject.c.h"
474474

Objects/typeobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#include "pycore_call.h"
55
#include "pycore_code.h" // CO_FAST_FREE
66
#include "pycore_compile.h" // _Py_Mangle()
7-
#include "pycore_initconfig.h"
7+
#include "pycore_initconfig.h" // _PyStatus_OK()
88
#include "pycore_moduleobject.h" // _PyModule_GetDef()
9-
#include "pycore_object.h"
10-
#include "pycore_pyerrors.h"
9+
#include "pycore_object.h" // _PyType_HasFeature()
10+
#include "pycore_pyerrors.h" // _PyErr_Occurred()
1111
#include "pycore_pystate.h" // _PyThreadState_GET()
1212
#include "pycore_unionobject.h" // _Py_union_type_or
13-
#include "frameobject.h"
14-
#include "pycore_frame.h"
13+
#include "frameobject.h" // PyFrameObject
14+
#include "pycore_frame.h" // InterpreterFrame
1515
#include "opcode.h" // MAKE_CELL
1616
#include "structmember.h" // PyMemberDef
1717

Parser/tokenizer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#define PY_SSIZE_T_CLEAN
55
#include "Python.h"
6+
#include "pycore_call.h" // _PyObject_CallNoArgs()
67

78
#include <ctype.h>
89
#include <assert.h>

Python/bltinmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Python.h"
44
#include <ctype.h>
55
#include "pycore_ast.h" // _PyAST_Validate()
6+
#include "pycore_call.h" // _PyObject_CallNoArgs()
67
#include "pycore_compile.h" // _PyAST_Compile()
78
#include "pycore_object.h" // _Py_AddToAllObjects()
89
#include "pycore_pyerrors.h" // _PyErr_NoMemory()

0 commit comments

Comments
 (0)