Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 15c5a50

Browse files
authored
gh-106320: Remove private pythonrun API (#108599)
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.
1 parent 301eb7e commit 15c5a50

File tree

9 files changed

+48
-24
lines changed

9 files changed

+48
-24
lines changed

Include/cpython/pythonrun.h

-24
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,11 @@
33
#endif
44

55
PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
6-
PyAPI_FUNC(int) _PyRun_SimpleFileObject(
7-
FILE *fp,
8-
PyObject *filename,
9-
int closeit,
10-
PyCompilerFlags *flags);
116
PyAPI_FUNC(int) PyRun_AnyFileExFlags(
127
FILE *fp,
138
const char *filename, /* decoded from the filesystem encoding */
149
int closeit,
1510
PyCompilerFlags *flags);
16-
PyAPI_FUNC(int) _PyRun_AnyFileObject(
17-
FILE *fp,
18-
PyObject *filename,
19-
int closeit,
20-
PyCompilerFlags *flags);
2111
PyAPI_FUNC(int) PyRun_SimpleFileExFlags(
2212
FILE *fp,
2313
const char *filename, /* decoded from the filesystem encoding */
@@ -35,10 +25,6 @@ PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
3525
FILE *fp,
3626
const char *filename, /* decoded from the filesystem encoding */
3727
PyCompilerFlags *flags);
38-
PyAPI_FUNC(int) _PyRun_InteractiveLoopObject(
39-
FILE *fp,
40-
PyObject *filename,
41-
PyCompilerFlags *flags);
4228

4329

4430
PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
@@ -69,15 +55,6 @@ PyAPI_FUNC(PyObject *) Py_CompileStringObject(
6955
#define Py_CompileString(str, p, s) Py_CompileStringExFlags((str), (p), (s), NULL, -1)
7056
#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags((str), (p), (s), (f), -1)
7157

72-
73-
PyAPI_FUNC(const char *) _Py_SourceAsString(
74-
PyObject *cmd,
75-
const char *funcname,
76-
const char *what,
77-
PyCompilerFlags *cf,
78-
PyObject **cmd_copy);
79-
80-
8158
/* A function flavor is also exported by libpython. It is required when
8259
libpython is accessed directly rather than using header files which defines
8360
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
11491
#define PyRun_FileFlags(fp, p, s, g, l, flags) \
11592
PyRun_FileExFlags((fp), (p), (s), (g), (l), 0, (flags))
11693

117-
11894
/* Stuff with no proper home (yet) */
11995
PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, const char *);
12096
PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);

Include/internal/pycore_pythonrun.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef Py_INTERNAL_PYTHONRUN_H
2+
#define Py_INTERNAL_PYTHONRUN_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
11+
extern int _PyRun_SimpleFileObject(
12+
FILE *fp,
13+
PyObject *filename,
14+
int closeit,
15+
PyCompilerFlags *flags);
16+
17+
extern int _PyRun_AnyFileObject(
18+
FILE *fp,
19+
PyObject *filename,
20+
int closeit,
21+
PyCompilerFlags *flags);
22+
23+
extern int _PyRun_InteractiveLoopObject(
24+
FILE *fp,
25+
PyObject *filename,
26+
PyCompilerFlags *flags);
27+
28+
extern const char* _Py_SourceAsString(
29+
PyObject *cmd,
30+
const char *funcname,
31+
const char *what,
32+
PyCompilerFlags *cf,
33+
PyObject **cmd_copy);
34+
35+
#ifdef __cplusplus
36+
}
37+
#endif
38+
#endif // !Py_INTERNAL_PYTHONRUN_H
39+

Makefile.pre.in

+1
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,7 @@ PYTHON_HEADERS= \
17951795
$(srcdir)/Include/internal/pycore_pymem.h \
17961796
$(srcdir)/Include/internal/pycore_pymem_init.h \
17971797
$(srcdir)/Include/internal/pycore_pystate.h \
1798+
$(srcdir)/Include/internal/pycore_pythonrun.h \
17981799
$(srcdir)/Include/internal/pycore_pythread.h \
17991800
$(srcdir)/Include/internal/pycore_range.h \
18001801
$(srcdir)/Include/internal/pycore_runtime.h \

Modules/main.c

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0()
88
#include "pycore_pylifecycle.h" // _Py_PreInitializeFromPyArgv()
99
#include "pycore_pystate.h" // _PyInterpreterState_GET()
10+
#include "pycore_pythonrun.h" // _PyRun_AnyFileObject()
1011

1112
/* Includes for exit_sigint() */
1213
#include <stdio.h> // perror()

Modules/symtablemodule.c

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Python.h"
2+
#include "pycore_pythonrun.h" // _Py_SourceAsString()
23
#include "pycore_symtable.h" // struct symtable
34

45
#include "clinic/symtablemodule.c.h"

PCbuild/pythoncore.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@
259259
<ClInclude Include="..\Include\internal\pycore_pymem.h" />
260260
<ClInclude Include="..\Include\internal\pycore_pymem_init.h" />
261261
<ClInclude Include="..\Include\internal\pycore_pystate.h" />
262+
<ClInclude Include="..\Include\internal\pycore_pythonrun.h" />
262263
<ClInclude Include="..\Include\internal\pycore_pythread.h" />
263264
<ClInclude Include="..\Include\internal\pycore_range.h" />
264265
<ClInclude Include="..\Include\internal\pycore_runtime.h" />

PCbuild/pythoncore.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,9 @@
681681
<ClInclude Include="..\Include\internal\pycore_pystate.h">
682682
<Filter>Include\internal</Filter>
683683
</ClInclude>
684+
<ClInclude Include="..\Include\internal\pycore_pythonrun.h">
685+
<Filter>Include\internal</Filter>
686+
</ClInclude>
684687
<ClInclude Include="..\Include\internal\pycore_pythread.h">
685688
<Filter>Include\internal</Filter>
686689
</ClInclude>

Python/bltinmodule.c

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "pycore_object.h" // _Py_AddToAllObjects()
1313
#include "pycore_pyerrors.h" // _PyErr_NoMemory()
1414
#include "pycore_pystate.h" // _PyThreadState_GET()
15+
#include "pycore_pythonrun.h" // _Py_SourceAsString()
1516
#include "pycore_sysmodule.h" // _PySys_GetAttr()
1617
#include "pycore_tuple.h" // _PyTuple_FromArray()
1718

Python/pythonrun.c

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException, _Py_Offer_Suggestions
2222
#include "pycore_pylifecycle.h" // _Py_UnhandledKeyboardInterrupt
2323
#include "pycore_pystate.h" // _PyInterpreterState_GET()
24+
#include "pycore_pythonrun.h" // define _PyRun_InteractiveLoopObject()
2425
#include "pycore_sysmodule.h" // _PySys_Audit()
2526
#include "pycore_traceback.h" // _PyTraceBack_Print_Indented()
2627

0 commit comments

Comments
 (0)