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().
This commit is contained in:
Victor Stinner 2021-10-12 08:38:19 +02:00 committed by GitHub
parent be21706f37
commit d943d19172
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 89 additions and 64 deletions

View File

@ -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)
{

View File

@ -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

View File

@ -1,4 +1,5 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_long.h" // _PyLong_GetZero()
#include "structmember.h" // PyMemberDef

View File

@ -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>

View File

@ -1,4 +1,5 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "frameobject.h"
#include <stdbool.h>

View File

@ -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

View File

@ -1,4 +1,5 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include <ffi.h>
#ifdef MS_WIN32
#include <windows.h>

View File

@ -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

View File

@ -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"

View File

@ -1,4 +1,5 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "rotatingtree.h"
/************************************************************/

View File

@ -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");
@ -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;

View File

@ -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 */

View File

@ -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);
@ -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;
@ -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
@ -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) {
@ -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;
}
@ -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;
}

View File

@ -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()

View File

@ -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()

View File

@ -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"

View File

@ -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:

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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()

View File

@ -113,11 +113,12 @@ As a consequence of this, split keys have a maximum size of 16.
#include "Python.h"
#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 "pycore_dict.h"
#include "stringlib/eq.h" // unicode_eq()
/*[clinic input]

View File

@ -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()

View File

@ -2,6 +2,7 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_runtime.h" // _PyRuntime
#if defined(HAVE_GETC_UNLOCKED) && !defined(_Py_MEMORY_SANITIZER)

View File

@ -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 *);

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -465,10 +465,10 @@ later:
*/
#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"

View File

@ -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

View File

@ -3,6 +3,7 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include <ctype.h>
#include <assert.h>

View File

@ -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()

View File

@ -13,11 +13,11 @@
#include "pycore_abstract.h" // _PyIndex_Check()
#include "pycore_call.h" // _PyObject_FastCallDictTstate()
#include "pycore_ceval.h" // _PyEval_SignalAsyncExc()
#include "pycore_code.h"
#include "pycore_code.h" // saturating_increment()
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "pycore_moduleobject.h"
#include "pycore_moduleobject.h" // PyModuleObject
#include "pycore_pyerrors.h" // _PyErr_Fetch()
#include "pycore_pylifecycle.h" // _PyErr_Print()
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()

View File

@ -9,6 +9,7 @@ Copyright (c) Corporation for National Research Initiatives.
------------------------------------------------------------------------ */
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_interp.h" // PyInterpreterState.codec_search_path
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI

View File

@ -2,11 +2,12 @@
/* Error handling */
#include "Python.h"
#include "pycore_initconfig.h"
#include "pycore_pyerrors.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_initconfig.h" // _PyStatus_ERR()
#include "pycore_pyerrors.h" // _PyErr_Format()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_sysmodule.h"
#include "pycore_traceback.h"
#include "pycore_sysmodule.h" // _PySys_Audit()
#include "pycore_traceback.h" // _PyTraceBack_FromFrame()
#ifndef __STDC__
#ifndef MS_WINDOWS

View File

@ -9,11 +9,12 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_code.h" // _PyCode_New()
#include "pycore_hashtable.h" // _Py_hashtable_t
#include "longintrepr.h"
#include "code.h"
#include "marshal.h"
#include "pycore_hashtable.h"
#include "pycore_code.h" // _PyCode_New()
#include "marshal.h" // Py_MARSHAL_VERSION
/*[clinic input]
module marshal

View File

@ -15,21 +15,22 @@ Data members:
*/
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _Py_RecursionLimitLowerWaterMark()
#include "pycore_code.h" // _Py_QuickenedCount
#include "pycore_frame.h" // InterpreterFrame
#include "pycore_initconfig.h" // _PyStatus_EXCEPTION()
#include "pycore_object.h" // _PyObject_IS_GC()
#include "pycore_code.h" // _Py_QuickenedCount
#include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0()
#include "pycore_pyerrors.h" // _PyErr_Fetch()
#include "pycore_pylifecycle.h" // _PyErr_WriteUnraisableDefaultHook()
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_tuple.h" // _PyTuple_FromArray()
#include "pycore_structseq.h" // PyStructSequence_InitType()
#include "pycore_tuple.h" // _PyTuple_FromArray()
#include "code.h"
#include "frameobject.h" // PyFrame_GetBack()
#include "pycore_frame.h"
#include "pydtrace.h"
#include "osdefs.h" // DELIM
#include "stdlib_module_names.h" // _Py_stdlib_module_names

View File

@ -942,7 +942,8 @@ class PyBuildExt(build_ext):
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
# profiler (_lsprof is for cProfile.py)
self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c'],
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
# static Unicode character database
self.add(Extension('unicodedata', ['unicodedata.c'],
depends=['unicodedata_db.h', 'unicodename_db.h'],