gh-106320: Remove private _PySys functions (#108452)
https://github.com/python/cpython/commit/a071ecb4d13595f3580cf82061dcd7b39cd... commit: a071ecb4d13595f3580cf82061dcd7b39cd475c5 branch: main author: Victor Stinner <vstinner@python.org> committer: vstinner <vstinner@python.org> date: 2023-08-24T20:02:09Z summary: gh-106320: Remove private _PySys functions (#108452) Move private functions to the internal C API (pycore_sysmodule.h): * _PySys_GetAttr() * _PySys_GetSizeOf() No longer export most of these functions. Fix also a typo in Include/cpython/optimizer.h: add a missing space. files: M Include/cpython/optimizer.h M Include/cpython/sysmodule.h M Include/internal/pycore_sysmodule.h M Modules/_io/bytesio.c M Modules/_pickle.c M Modules/_threadmodule.c M Modules/faulthandler.c M Python/_warnings.c M Python/bltinmodule.c M Python/intrinsics.c M Python/sysmodule.c M Python/traceback.c diff --git a/Include/cpython/optimizer.h b/Include/cpython/optimizer.h index e3fe0e8f0ffd5..10457afc180a0 100644 --- a/Include/cpython/optimizer.h +++ b/Include/cpython/optimizer.h @@ -38,7 +38,7 @@ PyAPI_FUNC(void) PyUnstable_SetOptimizer(_PyOptimizerObject* optimizer); PyAPI_FUNC(_PyOptimizerObject *) PyUnstable_GetOptimizer(void); -PyAPI_FUNC(_PyExecutorObject *)PyUnstable_GetExecutor(PyCodeObject *code, int offset); +PyAPI_FUNC(_PyExecutorObject *) PyUnstable_GetExecutor(PyCodeObject *code, int offset); struct _PyInterpreterFrame * _PyOptimizer_BackEdge(struct _PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNIT *dest, PyObject **stack_pointer); diff --git a/Include/cpython/sysmodule.h b/Include/cpython/sysmodule.h index 19d9dddc344a4..e028fb7ecd523 100644 --- a/Include/cpython/sysmodule.h +++ b/Include/cpython/sysmodule.h @@ -2,11 +2,6 @@ # error "this header file must not be included directly" #endif -PyAPI_FUNC(PyObject *) _PySys_GetAttr(PyThreadState *tstate, - PyObject *name); - -PyAPI_FUNC(size_t) _PySys_GetSizeOf(PyObject *); - typedef int(*Py_AuditHookFunction)(const char *, PyObject *, void *); PyAPI_FUNC(int) PySys_Audit( diff --git a/Include/internal/pycore_sysmodule.h b/Include/internal/pycore_sysmodule.h index aec9c2060fd0c..9b8eafd3d6cfd 100644 --- a/Include/internal/pycore_sysmodule.h +++ b/Include/internal/pycore_sysmodule.h @@ -8,6 +8,12 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif +// Export for '_pickle' shared extension +PyAPI_FUNC(PyObject*) _PySys_GetAttr(PyThreadState *tstate, PyObject *name); + +// Export for '_pickle' shared extension +PyAPI_FUNC(size_t) _PySys_GetSizeOf(PyObject *); + extern int _PySys_Audit( PyThreadState *tstate, const char *event, diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index 3ab503c9e3998..f3074203f54ea 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -1,5 +1,7 @@ #include "Python.h" #include "pycore_object.h" +#include "pycore_sysmodule.h" // _PySys_GetSizeOf() + #include <stddef.h> // offsetof() #include "_iomodule.h" diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 4f26ffe27d75f..b97524856eeca 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -17,10 +17,11 @@ #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_runtime.h" // _Py_ID() #include "pycore_setobject.h" // _PySet_NextEntry() - +#include "pycore_sysmodule.h" // _PySys_GetAttr() #include <stdlib.h> // strtol() + PyDoc_STRVAR(pickle_module_doc, "Optimized C implementation for the Python pickle module."); diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 229abfba82d1a..2cf866c5a1141 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -9,6 +9,7 @@ #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_pylifecycle.h" #include "pycore_pystate.h" // _PyThreadState_SetCurrent() +#include "pycore_sysmodule.h" // _PySys_GetAttr() #include "pycore_weakref.h" // _PyWeakref_GET_REF() #include <stddef.h> // offsetof() diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index d8cfc13a7dc6d..5ec34d4e99c80 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -3,6 +3,7 @@ #include "pycore_pyerrors.h" // _Py_DumpExtensionModules #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_signal.h" // Py_NSIG +#include "pycore_sysmodule.h" // _PySys_GetAttr() #include "pycore_traceback.h" // _Py_DumpTracebackThreads #include <object.h> diff --git a/Python/_warnings.c b/Python/_warnings.c index 40ec5f613d5bf..9e562d7ba7f6a 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -7,6 +7,8 @@ #include "pycore_pyerrors.h" #include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing() #include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_sysmodule.h" // _PySys_GetAttr() + #include "clinic/_warnings.c.h" #define MODULE_NAME "_warnings" diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 787f53fae354d..ac9bc72fe80d6 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -12,6 +12,7 @@ #include "pycore_object.h" // _Py_AddToAllObjects() #include "pycore_pyerrors.h" // _PyErr_NoMemory() #include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_sysmodule.h" // _PySys_GetAttr() #include "pycore_tuple.h" // _PyTuple_FromArray() #include "clinic/bltinmodule.c.h" diff --git a/Python/intrinsics.c b/Python/intrinsics.c index 5267c10238e62..fefee0fc4ebbe 100644 --- a/Python/intrinsics.c +++ b/Python/intrinsics.c @@ -4,10 +4,11 @@ #include "Python.h" #include "pycore_frame.h" #include "pycore_function.h" -#include "pycore_runtime.h" #include "pycore_global_objects.h" #include "pycore_intrinsics.h" #include "pycore_pyerrors.h" +#include "pycore_runtime.h" +#include "pycore_sysmodule.h" // _PySys_GetAttr() #include "pycore_typevarobject.h" diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 94d0f01f7477a..0ec763c7aa7cf 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -31,6 +31,7 @@ Data members: #include "pycore_pymem.h" // _PyMem_SetDefaultAllocator() #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_structseq.h" // _PyStructSequence_InitBuiltinWithFlags() +#include "pycore_sysmodule.h" // Define _PySys_GetSizeOf() #include "pycore_tuple.h" // _PyTuple_FromArray() #include "frameobject.h" // PyFrame_FastToLocalsWithError() diff --git a/Python/traceback.c b/Python/traceback.c index 61ace38275355..657ddab1cbf61 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -13,6 +13,7 @@ #include "pycore_pyarena.h" // _PyArena_Free() #include "pycore_pyerrors.h" // _PyErr_GetRaisedException() #include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_sysmodule.h" // _PySys_GetAttr() #include "pycore_traceback.h" // EXCEPTION_TB_HEADER #include "../Parser/pegen.h" // _PyPegen_byte_offset_to_character_offset()
participants (1)
-
vstinner