Skip to content

Commit a81fca6

Browse files
authored
bpo-43244: Add pycore_compile.h header file (GH-25000)
Remove the compiler functions using "struct _mod" type, because the public AST C API was removed: * PyAST_Compile() * PyAST_CompileEx() * PyAST_CompileObject() * PyFuture_FromAST() * PyFuture_FromASTObject() These functions were undocumented and excluded from the limited C API. Rename functions: * PyAST_CompileObject() => _PyAST_Compile() * PyFuture_FromASTObject() => _PyFuture_FromAST() Moreover, _PyFuture_FromAST() is no longer exported (replace PyAPI_FUNC() with extern). _PyAST_Compile() remains exported for test_peg_generator. Remove also compatibility functions: * PyAST_Compile() * PyAST_CompileEx() * PyFuture_FromAST()
1 parent f0a6fde commit a81fca6

File tree

15 files changed

+87
-84
lines changed

15 files changed

+87
-84
lines changed

Doc/whatsnew/3.10.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,3 +1399,15 @@ Removed
13991399
``Yield`` macro which was conflict with the ``Yield`` name used by the
14001400
Windows ``<winbase.h>`` header. Use the Python :mod:`ast` module instead.
14011401
(Contributed by Victor Stinner in :issue:`43244`.)
1402+
1403+
* Remove the compiler functions using ``struct _mod`` type, because the public
1404+
AST C API was removed:
1405+
1406+
* ``PyAST_Compile()``
1407+
* ``PyAST_CompileEx()``
1408+
* ``PyAST_CompileObject()``
1409+
* ``PyFuture_FromAST()``
1410+
* ``PyFuture_FromASTObject()``
1411+
1412+
These functions were undocumented and excluded from the limited C API.
1413+
(Contributed by Victor Stinner in :issue:`43244`.)

Include/cpython/compile.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -47,40 +47,6 @@ typedef struct {
4747
#define FUTURE_GENERATOR_STOP "generator_stop"
4848
#define FUTURE_ANNOTATIONS "annotations"
4949

50-
struct _mod; // Type defined in pycore_ast.h
51-
52-
#define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar)
53-
PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx(
54-
struct _mod *mod,
55-
const char *filename, /* decoded from the filesystem encoding */
56-
PyCompilerFlags *flags,
57-
int optimize,
58-
PyArena *arena);
59-
PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject(
60-
struct _mod *mod,
61-
PyObject *filename,
62-
PyCompilerFlags *flags,
63-
int optimize,
64-
PyArena *arena);
65-
PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(
66-
struct _mod * mod,
67-
const char *filename /* decoded from the filesystem encoding */
68-
);
69-
PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject(
70-
struct _mod * mod,
71-
PyObject *filename
72-
);
73-
74-
/* _Py_Mangle is defined in compile.c */
75-
PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
76-
7750
#define PY_INVALID_STACK_EFFECT INT_MAX
7851
PyAPI_FUNC(int) PyCompile_OpcodeStackEffect(int opcode, int oparg);
7952
PyAPI_FUNC(int) PyCompile_OpcodeStackEffectWithJump(int opcode, int oparg, int jump);
80-
81-
typedef struct {
82-
int optimize;
83-
int ff_features;
84-
} _PyASTOptimizeState;
85-
86-
PyAPI_FUNC(int) _PyAST_Optimize(struct _mod *, PyArena *arena, _PyASTOptimizeState *state);

Include/internal/pycore_compile.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef Py_INTERNAL_COMPILE_H
2+
#define Py_INTERNAL_COMPILE_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+
struct _mod; // Type defined in pycore_ast.h
12+
13+
// Export the symbol for test_peg_generator (built as a library)
14+
PyAPI_FUNC(PyCodeObject*) _PyAST_Compile(
15+
struct _mod *mod,
16+
PyObject *filename,
17+
PyCompilerFlags *flags,
18+
int optimize,
19+
PyArena *arena);
20+
extern PyFutureFeatures* _PyFuture_FromAST(
21+
struct _mod * mod,
22+
PyObject *filename
23+
);
24+
25+
extern PyObject* _Py_Mangle(PyObject *p, PyObject *name);
26+
27+
typedef struct {
28+
int optimize;
29+
int ff_features;
30+
} _PyASTOptimizeState;
31+
32+
extern int _PyAST_Optimize(
33+
struct _mod *,
34+
PyArena *arena,
35+
_PyASTOptimizeState *state);
36+
37+
#ifdef __cplusplus
38+
}
39+
#endif
40+
#endif /* !Py_INTERNAL_COMPILE_H */

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ PYTHON_HEADERS= \
11461146
$(srcdir)/Include/internal/pycore_call.h \
11471147
$(srcdir)/Include/internal/pycore_ceval.h \
11481148
$(srcdir)/Include/internal/pycore_code.h \
1149+
$(srcdir)/Include/internal/pycore_compile.h \
11491150
$(srcdir)/Include/internal/pycore_condvar.h \
11501151
$(srcdir)/Include/internal/pycore_context.h \
11511152
$(srcdir)/Include/internal/pycore_dtoa.h \
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Remove the compiler functions using ``struct _mod`` type, because the public
2+
AST C API was removed:
3+
4+
* ``PyAST_Compile()``
5+
* ``PyAST_CompileEx()``
6+
* ``PyAST_CompileObject()``
7+
* ``PyFuture_FromAST()``
8+
* ``PyFuture_FromASTObject()``
9+
10+
These functions were undocumented and excluded from the limited C API.
11+
Patch by Victor Stinner.

Objects/typeobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "Python.h"
44
#include "pycore_call.h"
5+
#include "pycore_compile.h" // _Py_Mangle()
56
#include "pycore_initconfig.h"
67
#include "pycore_object.h"
78
#include "pycore_pyerrors.h"

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
<ClInclude Include="..\Include\internal\pycore_call.h" />
184184
<ClInclude Include="..\Include\internal\pycore_ceval.h" />
185185
<ClInclude Include="..\Include\internal\pycore_code.h" />
186+
<ClInclude Include="..\Include\internal\pycore_compile.h" />
186187
<ClInclude Include="..\Include\internal\pycore_condvar.h" />
187188
<ClInclude Include="..\Include\internal\pycore_context.h" />
188189
<ClInclude Include="..\Include\internal\pycore_dtoa.h" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,9 @@
510510
<ClInclude Include="..\Include\internal\pycore_code.h">
511511
<Filter>Include\internal</Filter>
512512
</ClInclude>
513+
<ClInclude Include="..\Include\internal\pycore_compile.h">
514+
<Filter>Include\internal</Filter>
515+
</ClInclude>
513516
<ClInclude Include="..\Include\internal\pycore_condvar.h">
514517
<Filter>Include\internal</Filter>
515518
</ClInclude>

Python/ast_opt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* AST Optimizer */
22
#include "Python.h"
33
#include "pycore_ast.h" // _PyAST_GetDocString()
4+
#include "pycore_compile.h" // _PyASTOptimizeState
45

56

67
static int

Python/bltinmodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <ctype.h>
55
#include "pycore_ast.h" // _PyAST_Validate()
66
#undef Yield /* undefine macro conflicting with <winbase.h> */
7+
#include "pycore_compile.h" // _PyAST_Compile()
78
#include "pycore_object.h" // _Py_AddToAllObjects()
89
#include "pycore_pyerrors.h" // _PyErr_NoMemory()
910
#include "pycore_pystate.h" // _PyThreadState_GET()
@@ -839,8 +840,8 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
839840
PyArena_Free(arena);
840841
goto error;
841842
}
842-
result = (PyObject*)PyAST_CompileObject(mod, filename,
843-
&cf, optimize, arena);
843+
result = (PyObject*)_PyAST_Compile(mod, filename,
844+
&cf, optimize, arena);
844845
PyArena_Free(arena);
845846
}
846847
goto finally;

0 commit comments

Comments
 (0)