]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106320: Create pycore_modsupport.h header file (#106355)
authorVictor Stinner <vstinner@python.org>
Mon, 3 Jul 2023 09:39:11 +0000 (11:39 +0200)
committerGitHub <noreply@github.com>
Mon, 3 Jul 2023 09:39:11 +0000 (09:39 +0000)
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.

20 files changed:
Include/cpython/modsupport.h
Include/internal/pycore_modsupport.h [new file with mode: 0644]
Makefile.pre.in
Modules/_operator.c
Objects/boolobject.c
Objects/call.c
Objects/enumobject.c
Objects/floatobject.c
Objects/listobject.c
Objects/moduleobject.c
Objects/rangeobject.c
Objects/setobject.c
Objects/tupleobject.c
Objects/typeobject.c
Objects/weakrefobject.c
PCbuild/pythoncore.vcxproj
PCbuild/pythoncore.vcxproj.filters
Python/bltinmodule.c
Python/instrumentation.c
Python/sysmodule.c

index a5d95d15440df1c02efd5a7fe28c28157219f13b..376336b13dcf8add1ac3007fd86a42eb3704ed9a 100644 (file)
@@ -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 (file)
index 0000000..e577c6b
--- /dev/null
@@ -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
+
index 7560d17e3796f067fc403499df34480053f59c18..dcb3b5eb06a1e99c7f965724796bd9868e1116c7 100644 (file)
@@ -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 \
index 153e9e9e2f92c4530cedb529c8fef3ea47f6ffa1..108f45fb6dad93736b670b6a1e67893dbb88e761 100644 (file)
@@ -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 {
index f43e26f3f24e778150c5123acd059bacdbcd4668..bbb187cb7121e7d3c89e4804ec011ea2b1e7b143 100644 (file)
@@ -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 <stddef.h>
index 16c41ffe1d09b57c72377d3ceda1f18ff7f1e5e1..5045c0dc92843ba6f1815c0b2e91631275e9b992 100644 (file)
@@ -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()
index c9d90584c26b7d50552bdd77abb876f8d6a39fe4..556666779d85229356a6641219bb661e0e9bde17 100644 (file)
@@ -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"
index 83a263c0d9c67e197cc797bcd53c29e0c8f4d2f3..fa55481f09dec0d03979053b89ce6787cd81446f 100644 (file)
@@ -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()
index f1f324f7439b43529d124277bb09338c8cc3f245..98fa08962b6aad3cfc537715488a715dacea0f71 100644 (file)
@@ -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 <stddef.h>
index bda25c881845ce6d6f158af2d933f4bffaeb55d1..d4fccae65244c50d8662733a78a08a043c4aa478 100644 (file)
@@ -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
 
 
index beb86b9623bdbc8db8bbc1855da72c2b0d2fbccc..6dc41d71287cab3a2ab5491bdfe9aaa29b10b698 100644 (file)
@@ -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
 
index 58f0ae73c0c403fa5e722d5258b528c92c89d484..4ac541b95097529fa32b2c17ba63f4ffc009c03b 100644 (file)
@@ -32,6 +32,7 @@
 */
 
 #include "Python.h"
+#include "pycore_modsupport.h"    // _PyArg_NoKwnames()
 #include "pycore_object.h"        // _PyObject_GC_UNTRACK()
 #include <stddef.h>               // offsetof()
 
index 991edcc86677de9376c0a94c1ac966c1b44a74cf..e85af2b75e47387829dda1c6729aaf8b58357538 100644 (file)
@@ -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]
index 3d3a63a75bd2fb94f5a33b72518ec11e83696742..87519efef081c379548b7818d4d1791ef17d7dea 100644 (file)
@@ -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()
index f3f6c86637e9de35b81c0060f2173ee17f1c9d82..bac3e79bb7c250e75ca23c8b67bc51513401f87c 100644 (file)
@@ -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
index 79ce2d3d14017ef35c620818167a589c39a69022..760962e4c4b6a9908d267b99df3285cac11d330b 100644 (file)
     <ClInclude Include="..\Include\internal\pycore_intrinsics.h" />
     <ClInclude Include="..\Include\internal\pycore_list.h" />
     <ClInclude Include="..\Include\internal\pycore_long.h" />
+    <ClInclude Include="..\Include\internal\pycore_modsupport.h" />
     <ClInclude Include="..\Include\internal\pycore_moduleobject.h" />
     <ClInclude Include="..\Include\internal\pycore_namespace.h" />
     <ClInclude Include="..\Include\internal\pycore_object.h" />
index d47a22909e1e3aa78fcc01419752ee86bb7995f0..aaebe1908e30dae93466a5d4b536f03fe9c912d7 100644 (file)
     <ClInclude Include="..\Include\internal\pycore_long.h">
       <Filter>Include\internal</Filter>
     </ClInclude>
+    <ClInclude Include="..\Include\internal\pycore_modsupport.h">
+      <Filter>Include\internal</Filter>
+    </ClInclude>
     <ClInclude Include="..\Include\internal\pycore_moduleobject.h">
       <Filter>Include\internal</Filter>
     </ClInclude>
index 68fe315338a54d78b1d64db95c1b17296b3f1574..9fe0067daa678ccd8f2338bac9230c2c9f13c440 100644 (file)
@@ -4,13 +4,14 @@
 #include <ctype.h>
 #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"
 
index 03d7d2f215af7c13902b5e1255a618f4f0c7802d..e29748f0ad98721b6bd1f415789b6663243367ec 100644 (file)
@@ -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"
index 56d771f70ef5382c295328e8981ea1a6ea32e362..0ac6edc5a16f88ae3f18575d26fae1e66158cff2 100644 (file)
@@ -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()