From c494fb333b57bdf43fc90189fc29a00c293b2987 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 24 Aug 2023 20:25:22 +0200 Subject: [PATCH] gh-106320: Remove private _PyEval function (#108433) Move private _PyEval functions to the internal C API (pycore_ceval.h): * _PyEval_GetBuiltin() * _PyEval_GetBuiltinId() * _PyEval_GetSwitchInterval() * _PyEval_MakePendingCalls() * _PyEval_SetProfile() * _PyEval_SetSwitchInterval() * _PyEval_SetTrace() No longer export most of these functions. --- Include/cpython/ceval.h | 10 ---------- Include/internal/pycore_ceval.h | 17 +++++++++++++++++ Modules/_lsprof.c | 1 + Modules/_queuemodule.c | 1 + Modules/_threadmodule.c | 1 + Modules/arraymodule.c | 1 + Modules/itertoolsmodule.c | 1 + Objects/bytearrayobject.c | 1 + Objects/bytesobject.c | 5 +++-- Objects/classobject.c | 1 + Objects/dictobject.c | 1 + Objects/genericaliasobject.c | 1 + Objects/iterobject.c | 1 + Objects/listobject.c | 1 + Objects/odictobject.c | 1 + Objects/rangeobject.c | 1 + Objects/setobject.c | 1 + Objects/tupleobject.c | 1 + Objects/unicodeobject.c | 2 ++ 19 files changed, 37 insertions(+), 12 deletions(-) diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index 5255d715142..78f74056616 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -4,14 +4,9 @@ PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *); PyAPI_FUNC(void) PyEval_SetProfileAllThreads(Py_tracefunc, PyObject *); -PyAPI_FUNC(int) _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg); PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *); PyAPI_FUNC(void) PyEval_SetTraceAllThreads(Py_tracefunc, PyObject *); -PyAPI_FUNC(int) _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg); -/* Helper to look up a builtin object */ -PyAPI_FUNC(PyObject *) _PyEval_GetBuiltin(PyObject *); -PyAPI_FUNC(PyObject *) _PyEval_GetBuiltinId(_Py_Identifier *); /* Look at the current frame's (if any) code's co_flags, and turn on the corresponding compiler flags in cf->cf_flags. Return 1 if any flag was set, else return 0. */ @@ -19,11 +14,6 @@ PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf); PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _PyInterpreterFrame *f, int exc); -PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); -PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); - -PyAPI_FUNC(int) _PyEval_MakePendingCalls(PyThreadState *); - PyAPI_FUNC(Py_ssize_t) PyUnstable_Eval_RequestCodeExtraIndex(freefunc); // Old name -- remove when this API changes: _Py_DEPRECATED_EXTERNALLY(3.12) static inline Py_ssize_t diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index db3dac48662..e9535023cec 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -15,6 +15,23 @@ extern "C" { struct pyruntimestate; struct _ceval_runtime_state; +// Export for '_lsprof' shared extension +PyAPI_FUNC(int) _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg); + +extern int _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg); + +// Helper to look up a builtin object +// Export for 'array' shared extension +PyAPI_FUNC(PyObject*) _PyEval_GetBuiltin(PyObject *); + +extern PyObject* _PyEval_GetBuiltinId(_Py_Identifier *); + +extern void _PyEval_SetSwitchInterval(unsigned long microseconds); +extern unsigned long _PyEval_GetSwitchInterval(void); + +// Export for '_queue' shared extension +PyAPI_FUNC(int) _PyEval_MakePendingCalls(PyThreadState *); + #ifndef Py_DEFAULT_RECURSION_LIMIT # define Py_DEFAULT_RECURSION_LIMIT 1000 #endif diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 257de4387c0..e7dcb6e1713 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -4,6 +4,7 @@ #include "Python.h" #include "pycore_call.h" // _PyObject_CallNoArgs() +#include "pycore_ceval.h" // _PyEval_SetProfile() #include "pycore_pystate.h" // _PyThreadState_GET() #include "rotatingtree.h" diff --git a/Modules/_queuemodule.c b/Modules/_queuemodule.c index b0a36f03694..b4bafb375c9 100644 --- a/Modules/_queuemodule.c +++ b/Modules/_queuemodule.c @@ -3,6 +3,7 @@ #endif #include "Python.h" +#include "pycore_ceval.h" // _PyEval_MakePendingCalls() #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_time.h" // _PyTime_t diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 52f44d04523..984747c44d7 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -3,6 +3,7 @@ /* Interface to Sjoerd's portable C thread library */ #include "Python.h" +#include "pycore_ceval.h" // _PyEval_MakePendingCalls() #include "pycore_interp.h" // _PyInterpreterState.threads.count #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_pylifecycle.h" diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 5c1e6cb9cff..309a36919f3 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -10,6 +10,7 @@ #include "Python.h" #include "pycore_bytesobject.h" // _PyBytes_Repeat #include "pycore_call.h" // _PyObject_CallMethod() +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_long.h" // _PyLong_FromByteArray() #include "pycore_moduleobject.h" // _PyModule_GetState() diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 0ab6d330e87..4ed34aa5bde 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -1,5 +1,6 @@ #include "Python.h" #include "pycore_call.h" // _PyObject_CallNoArgs() +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_long.h" // _PyLong_GetZero() #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_typeobject.h" // _PyType_GetModuleState() diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 18a24a369a6..67073190cc8 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -4,6 +4,7 @@ #include "pycore_abstract.h" // _PyIndex_Check() #include "pycore_bytes_methods.h" #include "pycore_bytesobject.h" +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_object.h" // _PyObject_GC_UNTRACK() #include "pycore_strhex.h" // _Py_strhex_with_sep() #include "pycore_long.h" // _PyLong_FromUnsignedChar() diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index afe9192720c..a2c1f4cf359 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2,11 +2,12 @@ #include "Python.h" #include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_bytesobject.h" // _PyBytes_Find(), _PyBytes_Repeat() #include "pycore_bytes_methods.h" // _Py_bytes_startswith() +#include "pycore_bytesobject.h" // _PyBytes_Find(), _PyBytes_Repeat() #include "pycore_call.h" // _PyObject_CallNoArgs() +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_format.h" // F_LJUST -#include "pycore_global_objects.h" // _Py_GET_GLOBAL_OBJECT() +#include "pycore_global_objects.h"// _Py_GET_GLOBAL_OBJECT() #include "pycore_initconfig.h" // _PyStatus_OK() #include "pycore_long.h" // _PyLong_DigitValue #include "pycore_object.h" // _PyObject_GC_TRACK diff --git a/Objects/classobject.c b/Objects/classobject.c index 5471045d777..618d88894de 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -2,6 +2,7 @@ #include "Python.h" #include "pycore_call.h" // _PyObject_VectorcallTstate() +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_object.h" #include "pycore_pyerrors.h" #include "pycore_pystate.h" // _PyThreadState_GET() diff --git a/Objects/dictobject.c b/Objects/dictobject.c index d98e9a395c7..7cbc49f9699 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -115,6 +115,7 @@ 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_ceval.h" // _PyEval_GetBuiltin() #include "pycore_code.h" // stats #include "pycore_dict.h" // PyDictKeysObject #include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c index faf517b66b9..bb505374610 100644 --- a/Objects/genericaliasobject.c +++ b/Objects/genericaliasobject.c @@ -1,6 +1,7 @@ // types.GenericAlias -- used to represent e.g. list[int]. #include "Python.h" +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_object.h" #include "pycore_unionobject.h" // _Py_union_type_or, _PyGenericAlias_Check diff --git a/Objects/iterobject.c b/Objects/iterobject.c index cf7cb8af52a..135ced9ea1f 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -3,6 +3,7 @@ #include "Python.h" #include "pycore_abstract.h" // _PyObject_HasLen() #include "pycore_call.h" // _PyObject_CallNoArgs() +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_object.h" // _PyObject_GC_TRACK() typedef struct { diff --git a/Objects/listobject.c b/Objects/listobject.c index c0da9dd9168..ad1840b0122 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2,6 +2,7 @@ #include "Python.h" #include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_interp.h" // PyInterpreterState.list #include "pycore_list.h" // struct _Py_list_state, _PyListIterObject #include "pycore_long.h" // _PyLong_DigitCount diff --git a/Objects/odictobject.c b/Objects/odictobject.c index e76d2ded61c..d7a0f914d41 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -465,6 +465,7 @@ later: */ #include "Python.h" +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_call.h" // _PyObject_CallNoArgs() #include "pycore_object.h" // _PyObject_GC_UNTRACK() #include "pycore_dict.h" // _Py_dict_lookup() diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 6e06bef9503..ce9eef69ad7 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -2,6 +2,7 @@ #include "Python.h" #include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_long.h" // _PyLong_GetZero() #include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_range.h" diff --git a/Objects/setobject.c b/Objects/setobject.c index c96b62e38ec..14b53c12dda 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -32,6 +32,7 @@ */ #include "Python.h" +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_dict.h" // _PyDict_Contains_KnownHash() #include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_object.h" // _PyObject_GC_UNTRACK() diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index b669a3dd852..d567839c5e3 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -3,6 +3,7 @@ #include "Python.h" #include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() #include "pycore_initconfig.h" // _PyStatus_OK() #include "pycore_modsupport.h" // _PyArg_NoKwnames() diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index c6876d4ca0e..6bbc2af258e 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -43,6 +43,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "pycore_atomic_funcs.h" // _Py_atomic_size_get() #include "pycore_bytes_methods.h" // _Py_bytes_lower() #include "pycore_bytesobject.h" // _PyBytes_Repeat() +#include "pycore_ceval.h" // _PyEval_GetBuiltin() #include "pycore_codecs.h" // _PyCodec_Lookup() #include "pycore_format.h" // F_LJUST #include "pycore_initconfig.h" // _PyStatus_OK() @@ -56,6 +57,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI #include "pycore_unicodeobject.h" // struct _Py_unicode_state #include "pycore_unicodeobject_generated.h" // _PyUnicode_InitStaticStrings() + #include "stringlib/eq.h" // unicode_eq() #include // ptrdiff_t