Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-45439: Move _PyObject_CallNoArgs() to pycore_call.h #28895

Merged
merged 1 commit into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 0 additions & 9 deletions Include/cpython/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,6 @@ _PyObject_FastCall(PyObject *func, PyObject *const *args, Py_ssize_t nargs)
return _PyObject_FastCallTstate(tstate, func, args, nargs);
}

/* Call a callable without any arguments
Private static inline function variant of public function
PyObject_CallNoArgs(). */
static inline PyObject *
_PyObject_CallNoArgs(PyObject *func) {
PyThreadState *tstate = PyThreadState_Get();
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
}

static inline PyObject *
PyObject_CallOneArg(PyObject *func, PyObject *arg)
{
Expand Down
7 changes: 7 additions & 0 deletions Include/internal/pycore_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ _PyObject_CallNoArgsTstate(PyThreadState *tstate, PyObject *func) {
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
}

// Private static inline function variant of public PyObject_CallNoArgs()
static inline PyObject *
_PyObject_CallNoArgs(PyObject *func) {
PyThreadState *tstate = PyThreadState_Get();
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
}

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_long.h" // _PyLong_GetZero()
#include "structmember.h" // PyMemberDef

Expand Down
1 change: 1 addition & 0 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ bytes(cdata)
#define PY_SSIZE_T_CLEAN

#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "structmember.h" // PyMemberDef

#include <ffi.h>
Expand Down
1 change: 1 addition & 0 deletions Modules/_ctypes/callbacks.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "frameobject.h"

#include <stdbool.h>
Expand Down
1 change: 1 addition & 0 deletions Modules/_ctypes/cfield.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Python.h"
#include "pycore_bitutils.h" // _Py_bswap32()
#include "pycore_call.h" // _PyObject_CallNoArgs()

#include <ffi.h>
#ifdef MS_WIN32
Expand Down
1 change: 1 addition & 0 deletions Modules/_ctypes/stgdict.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include <ffi.h>
#ifdef MS_WIN32
#include <windows.h>
Expand Down
1 change: 1 addition & 0 deletions Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_object.h" // _PyObject_GC_TRACK
Expand Down
1 change: 1 addition & 0 deletions Modules/_io/bufferedio.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_object.h"
#include "structmember.h" // PyMemberDef
#include "_iomodule.h"
Expand Down
1 change: 1 addition & 0 deletions Modules/_lsprof.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "rotatingtree.h"

/************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ step_callback(sqlite3_context *context, int argc, sqlite3_value **params)
if (*aggregate_instance == NULL) {
callback_context *ctx = (callback_context *)sqlite3_user_data(context);
assert(ctx != NULL);
*aggregate_instance = _PyObject_CallNoArgs(ctx->callable);
*aggregate_instance = PyObject_CallNoArgs(ctx->callable);
if (!*aggregate_instance) {
set_sqlite_error(context,
"user-defined aggregate's '__init__' method raised error");
Expand Down Expand Up @@ -1008,7 +1008,7 @@ progress_callback(void *ctx)

assert(ctx != NULL);
PyObject *callable = ((callback_context *)ctx)->callable;
ret = _PyObject_CallNoArgs(callable);
ret = PyObject_CallNoArgs(callable);
if (!ret) {
/* abort query if error occurred */
rc = -1;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3773,7 +3773,7 @@ _password_callback(char *buf, int size, int rwflag, void *userdata)
}

if (pw_info->callable) {
fn_ret = _PyObject_CallNoArgs(pw_info->callable);
fn_ret = PyObject_CallNoArgs(pw_info->callable);
if (!fn_ret) {
/* TODO: It would be nice to move _ctypes_add_traceback() into the
core python API, so we could use it to add a frame here */
Expand Down
12 changes: 6 additions & 6 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2866,7 +2866,7 @@ _make_call(void *callable)
PyObject *rc;
int success;
PyGILState_STATE s = PyGILState_Ensure();
rc = _PyObject_CallNoArgs((PyObject *)callable);
rc = PyObject_CallNoArgs((PyObject *)callable);
success = (rc != NULL);
Py_XDECREF(rc);
PyGILState_Release(s);
Expand Down Expand Up @@ -2937,7 +2937,7 @@ static int _pending_callback(void *arg)
{
/* we assume the argument is callable object to which we own a reference */
PyObject *callable = (PyObject *)arg;
PyObject *r = _PyObject_CallNoArgs(callable);
PyObject *r = PyObject_CallNoArgs(callable);
Py_DECREF(callable);
Py_XDECREF(r);
return r != NULL ? 0 : -1;
Expand Down Expand Up @@ -3729,7 +3729,7 @@ slot_tp_del(PyObject *self)
/* Execute __del__ method, if any. */
del = _PyObject_LookupSpecial(self, &PyId___tp_del__);
if (del != NULL) {
res = _PyObject_CallNoArgs(del);
res = PyObject_CallNoArgs(del);
if (res == NULL)
PyErr_WriteUnraisable(del);
else
Expand Down Expand Up @@ -4358,7 +4358,7 @@ temporary_c_thread(void *data)
/* Allocate a Python thread state for this thread */
state = PyGILState_Ensure();

res = _PyObject_CallNoArgs(test_c_thread->callback);
res = PyObject_CallNoArgs(test_c_thread->callback);
Py_CLEAR(test_c_thread->callback);

if (res == NULL) {
Expand Down Expand Up @@ -4893,7 +4893,7 @@ check_pyobject_freed_is_freed(PyObject *self, PyObject *Py_UNUSED(args))
#ifdef _Py_ADDRESS_SANITIZER
Py_RETURN_NONE;
#else
PyObject *op = _PyObject_CallNoArgs((PyObject *)&PyBaseObject_Type);
PyObject *op = PyObject_CallNoArgs((PyObject *)&PyBaseObject_Type);
if (op == NULL) {
return NULL;
}
Expand Down Expand Up @@ -5271,7 +5271,7 @@ bad_get(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
return NULL;
}

PyObject *res = _PyObject_CallNoArgs(cls);
PyObject *res = PyObject_CallNoArgs(cls);
if (res == NULL) {
return NULL;
}
Expand Down
3 changes: 1 addition & 2 deletions Modules/itertoolsmodule.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@


#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "pycore_tuple.h" // _PyTuple_ITEMS()
Expand Down
1 change: 1 addition & 0 deletions Modules/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Python interpreter main program */

#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_initconfig.h" // _PyArgv
#include "pycore_interp.h" // _PyInterpreterState.sysdict
#include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0()
Expand Down
3 changes: 2 additions & 1 deletion Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ raised for division by zero and mod by zero.

#include "Python.h"
#include "pycore_bitutils.h" // _Py_bit_length()
#include "pycore_dtoa.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_dtoa.h" // _Py_dg_infinity()
#include "pycore_long.h" // _PyLong_GetZero()
#include "_math.h"

Expand Down
3 changes: 2 additions & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#define PY_SSIZE_T_CLEAN

#include "Python.h"
#include "pycore_fileutils.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_fileutils.h" // _Py_closerange()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#ifdef MS_WINDOWS
/* include <windows.h> early to avoid conflict with pycore_condvar.h:
Expand Down
2 changes: 1 addition & 1 deletion Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "pycore_atomic.h" // _Py_atomic_int
#include "pycore_call.h" // _PyObject_Call()
#include "pycore_ceval.h" // _PyEval_SignalReceived()
#include "pycore_frame.h"
#include "pycore_frame.h" // InterpreterFrame
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_pyerrors.h" // _PyErr_SetString()
#include "pycore_pylifecycle.h" // NSIG
Expand Down
1 change: 1 addition & 0 deletions Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Python.h"
#include "pycore_abstract.h" // _PyIndex_Check()
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
#include "pycore_object.h" // _Py_CheckSlotResult()
#include "pycore_pyerrors.h" // _PyErr_Occurred()
Expand Down
1 change: 1 addition & 0 deletions Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Python.h"
#include "pycore_abstract.h" // _PyIndex_Check()
#include "pycore_bytes_methods.h" // _Py_bytes_startswith()
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_format.h" // F_LJUST
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_object.h" // _PyObject_GC_TRACK
Expand Down
1 change: 1 addition & 0 deletions Objects/complexobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/* Submitted by Jim Hugunin */

#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_object.h" // _PyObject_Init()
#include "pycore_pymath.h" // _Py_ADJUST_ERANGE2()
Expand Down
15 changes: 8 additions & 7 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ As a consequence of this, split keys have a maximum size of 16.
#define PyDict_MINSIZE 8

#include "Python.h"
#include "pycore_bitutils.h" // _Py_bit_length
#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "pycore_pyerrors.h" // _PyErr_Fetch()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_dict.h"
#include "stringlib/eq.h" // unicode_eq()
#include "pycore_bitutils.h" // _Py_bit_length
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_dict.h" // PyDictKeysObject
#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "pycore_pyerrors.h" // _PyErr_Fetch()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "stringlib/eq.h" // unicode_eq()

/*[clinic input]
class dict "PyDictObject *" "&PyDict_Type"
Expand Down
1 change: 1 addition & 0 deletions Objects/enumobject.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* enumerate object */

#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_long.h" // _PyLong_GetOne()
#include "pycore_object.h" // _PyObject_GC_TRACK()

Expand Down
3 changes: 2 additions & 1 deletion Objects/fileobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_runtime.h" // _PyRuntime
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_runtime.h" // _PyRuntime

#if defined(HAVE_GETC_UNLOCKED) && !defined(_Py_MEMORY_SANITIZER)
/* clang MemorySanitizer doesn't yet understand getc_unlocked. */
Expand Down
9 changes: 5 additions & 4 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* Generator object implementation */

#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _PyEval_EvalFrame()
#include "pycore_object.h"
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_pyerrors.h" // _PyErr_ClearExcState()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "frameobject.h"
#include "pycore_frame.h"
#include "pycore_frame.h" // InterpreterFrame
#include "frameobject.h" // PyFrameObject
#include "structmember.h" // PyMemberDef
#include "opcode.h"
#include "opcode.h" // YIELD_FROM

static PyObject *gen_close(PyGenObject *, PyObject *);
static PyObject *async_gen_asend_new(PyAsyncGenObject *, PyObject *);
Expand Down
3 changes: 2 additions & 1 deletion Objects/iterobject.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* Iterator objects */

#include "Python.h"
#include "pycore_object.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_object.h" // _PyObject_GC_TRACK()

typedef struct {
PyObject_HEAD
Expand Down
1 change: 1 addition & 0 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Module object implementation */

#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_interp.h" // PyInterpreterState.importlib
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_moduleobject.h" // _PyModule_GetDef()
Expand Down
13 changes: 7 additions & 6 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
/* Generic object operations; and implementation of None */

#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
#include "pycore_context.h"
#include "pycore_initconfig.h"
#include "pycore_object.h"
#include "pycore_pyerrors.h"
#include "pycore_pylifecycle.h"
#include "pycore_initconfig.h" // _PyStatus_EXCEPTION()
#include "pycore_object.h" // _PyType_CheckConsistency()
#include "pycore_pyerrors.h" // _PyErr_Occurred()
#include "pycore_pylifecycle.h" // _PyTypes_InitSlotDefs()
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_symtable.h" // PySTEntry_Type
#include "pycore_unionobject.h" // _PyUnion_Type
#include "frameobject.h"
#include "interpreteridobject.h"
#include "frameobject.h" // PyFrame_Type
#include "interpreteridobject.h" // _PyInterpreterID_Type

#ifdef Py_LIMITED_API
// Prevent recursive call _Py_IncRef() <=> Py_INCREF()
Expand Down
6 changes: 3 additions & 3 deletions Objects/odictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,10 @@ Potential Optimizations
*/

#include "Python.h"
#include "pycore_object.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_dict.h" // _Py_dict_lookup()
#include <stddef.h> // offsetof()
#include "pycore_dict.h"
#include <stddef.h>

#include "clinic/odictobject.c.h"

Expand Down
10 changes: 5 additions & 5 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#include "pycore_call.h"
#include "pycore_code.h" // CO_FAST_FREE
#include "pycore_compile.h" // _Py_Mangle()
#include "pycore_initconfig.h"
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_moduleobject.h" // _PyModule_GetDef()
#include "pycore_object.h"
#include "pycore_pyerrors.h"
#include "pycore_object.h" // _PyType_HasFeature()
#include "pycore_pyerrors.h" // _PyErr_Occurred()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_unionobject.h" // _Py_union_type_or
#include "frameobject.h"
#include "pycore_frame.h"
#include "frameobject.h" // PyFrameObject
#include "pycore_frame.h" // InterpreterFrame
#include "opcode.h" // MAKE_CELL
#include "structmember.h" // PyMemberDef

Expand Down
1 change: 1 addition & 0 deletions Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()

#include <ctype.h>
#include <assert.h>
Expand Down
1 change: 1 addition & 0 deletions Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Python.h"
#include <ctype.h>
#include "pycore_ast.h" // _PyAST_Validate()
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_compile.h" // _PyAST_Compile()
#include "pycore_object.h" // _Py_AddToAllObjects()
#include "pycore_pyerrors.h" // _PyErr_NoMemory()
Expand Down
Loading