From 35963da40fb7bc93c55d94caf58ff9e268df951d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 3 Jul 2023 11:39:11 +0200 Subject: [PATCH] gh-106320: Create pycore_modsupport.h header file (#106355) Remove the following functions from the C API, move them to the internal C API: add a new pycore_modsupport.h internal header file: * PyModule_CreateInitialized() * _PyArg_NoKwnames() * _Py_VaBuildStack() No longer export these functions. --- Include/cpython/modsupport.h | 12 ------------ Include/internal/pycore_modsupport.h | 29 ++++++++++++++++++++++++++++ Makefile.pre.in | 1 + Modules/_operator.c | 4 +++- Objects/boolobject.c | 5 +++-- Objects/call.c | 1 + Objects/enumobject.c | 1 + Objects/floatobject.c | 1 + Objects/listobject.c | 1 + Objects/moduleobject.c | 3 ++- Objects/rangeobject.c | 3 ++- Objects/setobject.c | 1 + Objects/tupleobject.c | 1 + Objects/typeobject.c | 1 + Objects/weakrefobject.c | 1 + PCbuild/pythoncore.vcxproj | 1 + PCbuild/pythoncore.vcxproj.filters | 3 +++ Python/bltinmodule.c | 3 ++- Python/instrumentation.c | 1 + Python/sysmodule.c | 1 + 20 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 Include/internal/pycore_modsupport.h diff --git a/Include/cpython/modsupport.h b/Include/cpython/modsupport.h index a5d95d15440..376336b13dc 100644 --- a/Include/cpython/modsupport.h +++ b/Include/cpython/modsupport.h @@ -11,12 +11,9 @@ PyAPI_FUNC(int) _PyArg_UnpackStack( ...); PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kwargs); -PyAPI_FUNC(int) _PyArg_NoKwnames(const char *funcname, PyObject *kwnames); PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args); #define _PyArg_NoKeywords(funcname, kwargs) \ ((kwargs) == NULL || _PyArg_NoKeywords((funcname), (kwargs))) -#define _PyArg_NoKwnames(funcname, kwnames) \ - ((kwnames) == NULL || _PyArg_NoKwnames((funcname), (kwnames))) #define _PyArg_NoPositional(funcname, args) \ ((args) == NULL || _PyArg_NoPositional((funcname), (args))) @@ -29,13 +26,6 @@ PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t, ((!_Py_ANY_VARARGS(max) && (min) <= (nargs) && (nargs) <= (max)) \ || _PyArg_CheckPositional((funcname), (nargs), (min), (max))) -PyAPI_FUNC(PyObject **) _Py_VaBuildStack( - PyObject **small_stack, - Py_ssize_t small_stack_len, - const char *format, - va_list va, - Py_ssize_t *p_nargs); - typedef struct _PyArg_Parser { int initialized; const char *format; @@ -83,5 +73,3 @@ PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywordsWithVararg( (minpos) <= (nargs) && (nargs) <= (maxpos) && (args) != NULL) ? (args) : \ _PyArg_UnpackKeywords((args), (nargs), (kwargs), (kwnames), (parser), \ (minpos), (maxpos), (minkw), (buf))) - -PyAPI_FUNC(PyObject *) _PyModule_CreateInitialized(PyModuleDef*, int apiver); diff --git a/Include/internal/pycore_modsupport.h b/Include/internal/pycore_modsupport.h new file mode 100644 index 00000000000..e577c6ba856 --- /dev/null +++ b/Include/internal/pycore_modsupport.h @@ -0,0 +1,29 @@ +#ifndef Py_INTERNAL_MODSUPPORT_H +#define Py_INTERNAL_MODSUPPORT_H +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef Py_BUILD_CORE +# error "this header requires Py_BUILD_CORE define" +#endif + + +extern int _PyArg_NoKwnames(const char *funcname, PyObject *kwnames); +#define _PyArg_NoKwnames(funcname, kwnames) \ + ((kwnames) == NULL || _PyArg_NoKwnames((funcname), (kwnames))) + +extern PyObject ** _Py_VaBuildStack( + PyObject **small_stack, + Py_ssize_t small_stack_len, + const char *format, + va_list va, + Py_ssize_t *p_nargs); + +extern PyObject* _PyModule_CreateInitialized(PyModuleDef*, int apiver); + +#ifdef __cplusplus +} +#endif +#endif // !Py_INTERNAL_MODSUPPORT_H + diff --git a/Makefile.pre.in b/Makefile.pre.in index 7560d17e379..dcb3b5eb06a 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1761,6 +1761,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/internal/pycore_intrinsics.h \ $(srcdir)/Include/internal/pycore_list.h \ $(srcdir)/Include/internal/pycore_long.h \ + $(srcdir)/Include/internal/pycore_modsupport.h \ $(srcdir)/Include/internal/pycore_moduleobject.h \ $(srcdir)/Include/internal/pycore_namespace.h \ $(srcdir)/Include/internal/pycore_object.h \ diff --git a/Modules/_operator.c b/Modules/_operator.c index 153e9e9e2f9..108f45fb6da 100644 --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -1,7 +1,9 @@ #include "Python.h" +#include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_moduleobject.h" // _PyModule_GetState() -#include "structmember.h" // PyMemberDef #include "pycore_runtime.h" // _Py_ID() + +#include "structmember.h" // PyMemberDef #include "clinic/_operator.c.h" typedef struct { diff --git a/Objects/boolobject.c b/Objects/boolobject.c index f43e26f3f24..bbb187cb712 100644 --- a/Objects/boolobject.c +++ b/Objects/boolobject.c @@ -1,8 +1,9 @@ /* Boolean type, a subtype of int */ #include "Python.h" -#include "pycore_object.h" // _Py_FatalRefcountError() -#include "pycore_long.h" // FALSE_TAG TRUE_TAG +#include "pycore_long.h" // FALSE_TAG TRUE_TAG +#include "pycore_modsupport.h" // _PyArg_NoKwnames() +#include "pycore_object.h" // _Py_FatalRefcountError() #include "pycore_runtime.h" // _Py_ID() #include diff --git a/Objects/call.c b/Objects/call.c index 16c41ffe1d0..5045c0dc928 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -2,6 +2,7 @@ #include "pycore_call.h" // _PyObject_CallNoArgsTstate() #include "pycore_ceval.h" // _Py_EnterRecursiveCallTstate() #include "pycore_dict.h" // _PyDict_FromItems() +#include "pycore_modsupport.h" // _Py_VaBuildStack() #include "pycore_object.h" // _PyCFunctionWithKeywords_TrampolineCall() #include "pycore_pyerrors.h" // _PyErr_Occurred() #include "pycore_pystate.h" // _PyThreadState_GET() diff --git a/Objects/enumobject.c b/Objects/enumobject.c index c9d90584c26..556666779d8 100644 --- a/Objects/enumobject.c +++ b/Objects/enumobject.c @@ -3,6 +3,7 @@ #include "Python.h" #include "pycore_call.h" // _PyObject_CallNoArgs() #include "pycore_long.h" // _PyLong_GetOne() +#include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_object.h" // _PyObject_GC_TRACK() #include "clinic/enumobject.c.h" diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 83a263c0d9c..fa55481f09d 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -9,6 +9,7 @@ #include "pycore_initconfig.h" // _PyStatus_OK() #include "pycore_interp.h" // _PyInterpreterState.float_state #include "pycore_long.h" // _PyLong_GetOne() +#include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_object.h" // _PyObject_Init() #include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR #include "pycore_pystate.h" // _PyInterpreterState_GET() diff --git a/Objects/listobject.c b/Objects/listobject.c index f1f324f7439..98fa08962b6 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -5,6 +5,7 @@ #include "pycore_interp.h" // PyInterpreterState.list #include "pycore_list.h" // struct _Py_list_state, _PyListIterObject #include "pycore_long.h" // _PyLong_DigitCount +#include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_object.h" // _PyObject_GC_TRACK() #include "pycore_tuple.h" // _PyTuple_FromArray() #include diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index bda25c88184..d4fccae6524 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -5,8 +5,9 @@ #include "pycore_call.h" // _PyObject_CallNoArgs() #include "pycore_interp.h" // PyInterpreterState.importlib #include "pycore_object.h" // _PyType_AllocNoTrack -#include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_moduleobject.h" // _PyModule_GetDef() +#include "pycore_modsupport.h" // _PyModule_CreateInitialized() +#include "pycore_pystate.h" // _PyInterpreterState_GET() #include "structmember.h" // PyMemberDef diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index beb86b9623b..6dc41d71287 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -2,8 +2,9 @@ #include "Python.h" #include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_range.h" #include "pycore_long.h" // _PyLong_GetZero() +#include "pycore_modsupport.h" // _PyArg_NoKwnames() +#include "pycore_range.h" #include "pycore_tuple.h" // _PyTuple_ITEMS() #include "structmember.h" // PyMemberDef diff --git a/Objects/setobject.c b/Objects/setobject.c index 58f0ae73c0c..4ac541b9509 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -32,6 +32,7 @@ */ #include "Python.h" +#include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_object.h" // _PyObject_GC_UNTRACK() #include // offsetof() diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 991edcc8667..e85af2b75e4 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -5,6 +5,7 @@ #include "pycore_abstract.h" // _PyIndex_Check() #include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() #include "pycore_initconfig.h" // _PyStatus_OK() +#include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_object.h" // _PyObject_GC_TRACK(), _Py_FatalRefcountError() /*[clinic input] diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 3d3a63a75bd..87519efef08 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -8,6 +8,7 @@ #include "pycore_frame.h" // _PyInterpreterFrame #include "pycore_long.h" // _PyLong_IsNegative() #include "pycore_memoryobject.h" // _PyMemoryView_FromBufferProc() +#include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_moduleobject.h" // _PyModule_GetDef() #include "pycore_object.h" // _PyType_HasFeature() #include "pycore_pyerrors.h" // _PyErr_Occurred() diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index f3f6c86637e..bac3e79bb7c 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -1,4 +1,5 @@ #include "Python.h" +#include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_object.h" // _PyObject_GET_WEAKREFS_LISTPTR() #include "pycore_weakref.h" // _PyWeakref_GET_REF() #include "structmember.h" // PyMemberDef diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 79ce2d3d140..760962e4c4b 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -241,6 +241,7 @@ + diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index d47a22909e1..aaebe1908e3 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -627,6 +627,9 @@ Include\internal + + Include\internal + Include\internal diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 68fe315338a..9fe0067daa6 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -4,13 +4,14 @@ #include #include "pycore_ast.h" // _PyAST_Validate() #include "pycore_call.h" // _PyObject_CallNoArgs() +#include "pycore_ceval.h" // _PyEval_Vector() #include "pycore_compile.h" // _PyAST_Compile() #include "pycore_long.h" // _PyLong_CompactValue +#include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_object.h" // _Py_AddToAllObjects() #include "pycore_pyerrors.h" // _PyErr_NoMemory() #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_tuple.h" // _PyTuple_FromArray() -#include "pycore_ceval.h" // _PyEval_Vector() #include "clinic/bltinmodule.c.h" diff --git a/Python/instrumentation.c b/Python/instrumentation.c index 03d7d2f215a..e29748f0ad9 100644 --- a/Python/instrumentation.c +++ b/Python/instrumentation.c @@ -3,6 +3,7 @@ #include "pycore_frame.h" #include "pycore_interp.h" #include "pycore_long.h" +#include "pycore_modsupport.h" // _PyModule_CreateInitialized() #include "pycore_namespace.h" #include "pycore_object.h" #include "pycore_opcode.h" diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 56d771f70ef..0ac6edc5a16 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -20,6 +20,7 @@ Data members: #include "pycore_frame.h" // _PyInterpreterFrame #include "pycore_initconfig.h" // _PyStatus_EXCEPTION() #include "pycore_long.h" // _PY_LONG_MAX_STR_DIGITS_THRESHOLD +#include "pycore_modsupport.h" // _PyModule_CreateInitialized() #include "pycore_namespace.h" // _PyNamespace_New() #include "pycore_object.h" // _PyObject_IS_GC() #include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0()