]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106320: Remove private pythonrun API (#108599)
authorVictor Stinner <vstinner@python.org>
Tue, 29 Aug 2023 02:18:52 +0000 (04:18 +0200)
committerGitHub <noreply@github.com>
Tue, 29 Aug 2023 02:18:52 +0000 (04:18 +0200)
Remove these private functions from the public C API:

* _PyRun_AnyFileObject()
* _PyRun_InteractiveLoopObject()
* _PyRun_SimpleFileObject()
* _Py_SourceAsString()

Move them to the internal C API: add a new pycore_pythonrun.h header
file. No longer export these functions.

Include/cpython/pythonrun.h
Include/internal/pycore_pythonrun.h [new file with mode: 0644]
Makefile.pre.in
Modules/main.c
Modules/symtablemodule.c
PCbuild/pythoncore.vcxproj
PCbuild/pythoncore.vcxproj.filters
Python/bltinmodule.c
Python/pythonrun.c

index 3b2537e01b83b1b83214f734375efa1a77aa914d..edc40952254029f8c8f2927f4e3324a14d40fba6 100644 (file)
@@ -3,21 +3,11 @@
 #endif
 
 PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
-PyAPI_FUNC(int) _PyRun_SimpleFileObject(
-    FILE *fp,
-    PyObject *filename,
-    int closeit,
-    PyCompilerFlags *flags);
 PyAPI_FUNC(int) PyRun_AnyFileExFlags(
     FILE *fp,
     const char *filename,       /* decoded from the filesystem encoding */
     int closeit,
     PyCompilerFlags *flags);
-PyAPI_FUNC(int) _PyRun_AnyFileObject(
-    FILE *fp,
-    PyObject *filename,
-    int closeit,
-    PyCompilerFlags *flags);
 PyAPI_FUNC(int) PyRun_SimpleFileExFlags(
     FILE *fp,
     const char *filename,       /* decoded from the filesystem encoding */
@@ -35,10 +25,6 @@ PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
     FILE *fp,
     const char *filename,       /* decoded from the filesystem encoding */
     PyCompilerFlags *flags);
-PyAPI_FUNC(int) _PyRun_InteractiveLoopObject(
-    FILE *fp,
-    PyObject *filename,
-    PyCompilerFlags *flags);
 
 
 PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
@@ -69,15 +55,6 @@ PyAPI_FUNC(PyObject *) Py_CompileStringObject(
 #define Py_CompileString(str, p, s) Py_CompileStringExFlags((str), (p), (s), NULL, -1)
 #define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags((str), (p), (s), (f), -1)
 
-
-PyAPI_FUNC(const char *) _Py_SourceAsString(
-    PyObject *cmd,
-    const char *funcname,
-    const char *what,
-    PyCompilerFlags *cf,
-    PyObject **cmd_copy);
-
-
 /* A function flavor is also exported by libpython. It is required when
     libpython is accessed directly rather than using header files which defines
     macros below. On Windows, for example, PyAPI_FUNC() uses dllexport to
@@ -114,7 +91,6 @@ PyAPI_FUNC(PyObject *) PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject
 #define PyRun_FileFlags(fp, p, s, g, l, flags) \
     PyRun_FileExFlags((fp), (p), (s), (g), (l), 0, (flags))
 
-
 /* Stuff with no proper home (yet) */
 PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *);
 PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
diff --git a/Include/internal/pycore_pythonrun.h b/Include/internal/pycore_pythonrun.h
new file mode 100644 (file)
index 0000000..0bfc570
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef Py_INTERNAL_PYTHONRUN_H
+#define Py_INTERNAL_PYTHONRUN_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef Py_BUILD_CORE
+#  error "this header requires Py_BUILD_CORE define"
+#endif
+
+extern int _PyRun_SimpleFileObject(
+    FILE *fp,
+    PyObject *filename,
+    int closeit,
+    PyCompilerFlags *flags);
+
+extern int _PyRun_AnyFileObject(
+    FILE *fp,
+    PyObject *filename,
+    int closeit,
+    PyCompilerFlags *flags);
+
+extern int _PyRun_InteractiveLoopObject(
+    FILE *fp,
+    PyObject *filename,
+    PyCompilerFlags *flags);
+
+extern const char* _Py_SourceAsString(
+    PyObject *cmd,
+    const char *funcname,
+    const char *what,
+    PyCompilerFlags *cf,
+    PyObject **cmd_copy);
+
+#ifdef __cplusplus
+}
+#endif
+#endif  // !Py_INTERNAL_PYTHONRUN_H
+
index 310caa94b9e4764197a1b6d6ba31d8cb697bcb18..ad3e26c036408e181aa5e678cc2dffd73f8a3d5a 100644 (file)
@@ -1795,6 +1795,7 @@ PYTHON_HEADERS= \
                $(srcdir)/Include/internal/pycore_pymem.h \
                $(srcdir)/Include/internal/pycore_pymem_init.h \
                $(srcdir)/Include/internal/pycore_pystate.h \
+               $(srcdir)/Include/internal/pycore_pythonrun.h \
                $(srcdir)/Include/internal/pycore_pythread.h \
                $(srcdir)/Include/internal/pycore_range.h \
                $(srcdir)/Include/internal/pycore_runtime.h \
index a5c009321d607fdbb77a7652aed869825500b716..7f88c97207475b953314479a674e0a5c6d4e8187 100644 (file)
@@ -7,6 +7,7 @@
 #include "pycore_pathconfig.h"    // _PyPathConfig_ComputeSysPath0()
 #include "pycore_pylifecycle.h"   // _Py_PreInitializeFromPyArgv()
 #include "pycore_pystate.h"       // _PyInterpreterState_GET()
+#include "pycore_pythonrun.h"     // _PyRun_AnyFileObject()
 
 /* Includes for exit_sigint() */
 #include <stdio.h>                // perror()
index 1cc319cc3410d8b0676d5a0bd22870a6164aa6f8..dba80034d310af3b7772cb5d47832b76b5303d24 100644 (file)
@@ -1,4 +1,5 @@
 #include "Python.h"
+#include "pycore_pythonrun.h"     // _Py_SourceAsString()
 #include "pycore_symtable.h"      // struct symtable
 
 #include "clinic/symtablemodule.c.h"
index 9ab84702d1f2d26bcb87b836f4855c37fe09f372..0b0f5ad0fdb9cd457990e62349d6a551885dde75 100644 (file)
     <ClInclude Include="..\Include\internal\pycore_pymem.h" />
     <ClInclude Include="..\Include\internal\pycore_pymem_init.h" />
     <ClInclude Include="..\Include\internal\pycore_pystate.h" />
+    <ClInclude Include="..\Include\internal\pycore_pythonrun.h" />
     <ClInclude Include="..\Include\internal\pycore_pythread.h" />
     <ClInclude Include="..\Include\internal\pycore_range.h" />
     <ClInclude Include="..\Include\internal\pycore_runtime.h" />
index d5c53a0c64b29c4f812e20715a1c0efa68b98ab4..c70b8017935d733c86052e6f543469b925299588 100644 (file)
     <ClInclude Include="..\Include\internal\pycore_pystate.h">
       <Filter>Include\internal</Filter>
     </ClInclude>
+    <ClInclude Include="..\Include\internal\pycore_pythonrun.h">
+      <Filter>Include\internal</Filter>
+    </ClInclude>
     <ClInclude Include="..\Include\internal\pycore_pythread.h">
       <Filter>Include\internal</Filter>
     </ClInclude>
index ac9bc72fe80d6c12d8c0e977727d2cf9eb196a33..30dd717b0fea2923724ea168e78eb725dee4ee75 100644 (file)
@@ -12,6 +12,7 @@
 #include "pycore_object.h"        // _Py_AddToAllObjects()
 #include "pycore_pyerrors.h"      // _PyErr_NoMemory()
 #include "pycore_pystate.h"       // _PyThreadState_GET()
+#include "pycore_pythonrun.h"     // _Py_SourceAsString()
 #include "pycore_sysmodule.h"     // _PySys_GetAttr()
 #include "pycore_tuple.h"         // _PyTuple_FromArray()
 
index a2b50c021ce9e491cd65070ad4c1471d6233aa5e..231ac78146a0e6ecb12a5a3bf8e9125befa7d369 100644 (file)
@@ -21,6 +21,7 @@
 #include "pycore_pyerrors.h"      // _PyErr_GetRaisedException, _Py_Offer_Suggestions
 #include "pycore_pylifecycle.h"   // _Py_UnhandledKeyboardInterrupt
 #include "pycore_pystate.h"       // _PyInterpreterState_GET()
+#include "pycore_pythonrun.h"     // define _PyRun_InteractiveLoopObject()
 #include "pycore_sysmodule.h"     // _PySys_Audit()
 #include "pycore_traceback.h"     // _PyTraceBack_Print_Indented()