Skip to content

Commit 526fdeb

Browse files
authored
bpo-43244: Add pycore_ast.h header file (GH-24908)
Move _PyAST_GetDocString() and _PyAST_ExprAsUnicode() functions the internal C API: from Include/ast.h to a new Include/internal/pycore_ast.h header file. Don't export these functions anymore: replace PyAPI_FUNC() with extern. Remove also unused includes.
1 parent b4536e1 commit 526fdeb

File tree

8 files changed

+37
-21
lines changed

8 files changed

+37
-21
lines changed

Include/ast.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ extern "C" {
99

1010
PyAPI_FUNC(int) PyAST_Validate(mod_ty);
1111

12-
/* _PyAST_ExprAsUnicode is defined in ast_unparse.c */
13-
PyAPI_FUNC(PyObject *) _PyAST_ExprAsUnicode(expr_ty);
14-
15-
/* Return the borrowed reference to the first literal string in the
16-
sequence of statements or NULL if it doesn't start from a literal string.
17-
Doesn't set exception. */
18-
PyAPI_FUNC(PyObject *) _PyAST_GetDocString(asdl_stmt_seq *);
19-
2012
#ifdef __cplusplus
2113
}
2214
#endif

Include/internal/pycore_ast.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef Py_INTERNAL_AST_H
2+
#define Py_INTERNAL_AST_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+
#include "Python-ast.h" // expr_ty
12+
13+
/* _PyAST_ExprAsUnicode is defined in ast_unparse.c */
14+
extern PyObject* _PyAST_ExprAsUnicode(expr_ty);
15+
16+
/* Return the borrowed reference to the first literal string in the
17+
sequence of statements or NULL if it doesn't start from a literal string.
18+
Doesn't set exception. */
19+
extern PyObject* _PyAST_GetDocString(asdl_stmt_seq *);
20+
21+
#ifdef __cplusplus
22+
}
23+
#endif
24+
#endif /* !Py_INTERNAL_AST_H */
25+

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ PYTHON_HEADERS= \
11351135
\
11361136
$(srcdir)/Include/internal/pycore_abstract.h \
11371137
$(srcdir)/Include/internal/pycore_accu.h \
1138+
$(srcdir)/Include/internal/pycore_ast.h \
11381139
$(srcdir)/Include/internal/pycore_ast_state.h \
11391140
$(srcdir)/Include/internal/pycore_atomic.h \
11401141
$(srcdir)/Include/internal/pycore_atomic_funcs.h \

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
<ClInclude Include="..\Include\import.h" />
176176
<ClInclude Include="..\Include\internal\pycore_abstract.h" />
177177
<ClInclude Include="..\Include\internal\pycore_accu.h" />
178+
<ClInclude Include="..\Include\internal\pycore_ast.h" />
178179
<ClInclude Include="..\Include\internal\pycore_ast_state.h" />
179180
<ClInclude Include="..\Include\internal\pycore_atomic.h" />
180181
<ClInclude Include="..\Include\internal\pycore_atomic_funcs.h" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@
486486
<ClInclude Include="..\Include\internal\pycore_accu.h">
487487
<Filter>Include\internal</Filter>
488488
</ClInclude>
489+
<ClInclude Include="..\Include\internal\pycore_ast.h">
490+
<Filter>Include\internal</Filter>
491+
</ClInclude>
489492
<ClInclude Include="..\Include\internal\pycore_ast_state.h">
490493
<Filter>Include\internal</Filter>
491494
</ClInclude>

Python/ast_opt.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* AST Optimizer */
22
#include "Python.h"
3-
#include "Python-ast.h"
4-
#include "ast.h"
3+
#include "pycore_ast.h" // _PyAST_GetDocString()
54

65

76
static int

Python/compile.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@
2222
*/
2323

2424
#include "Python.h"
25+
#include "pycore_ast.h" // _PyAST_GetDocString()
2526
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
2627
#include "pycore_long.h" // _PyLong_GetZero()
2728

28-
#include "Python-ast.h"
29-
#include "ast.h"
30-
#include "code.h"
31-
#include "symtable.h"
29+
#include "symtable.h" // struct symtable
3230
#define NEED_OPCODE_JUMP_TABLES
33-
#include "opcode.h"
34-
#include "wordcode_helpers.h"
31+
#include "opcode.h" // EXTENDED_ARG
32+
#include "wordcode_helpers.h" // instrsize()
33+
3534

3635
#define DEFAULT_BLOCK_SIZE 16
3736
#define DEFAULT_BLOCKS 8

Python/future.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#include "Python.h"
2-
#include "Python-ast.h"
3-
#include "token.h"
4-
#include "code.h"
5-
#include "symtable.h"
6-
#include "ast.h"
2+
#include "pycore_ast.h" // _PyAST_GetDocString()
73

84
#define UNDEFINED_FUTURE_FEATURE "future feature %.100s is not defined"
95
#define ERR_LATE_FUTURE \

0 commit comments

Comments
 (0)