Skip to content

Commit 5f2df88

Browse files
authored
bpo-35177: Add dependencies between header files (pythonGH-10361)
* ast.h now includes Python-ast.h and node.h * parsetok.h now includes node.h and grammar.h * symtable.h now includes Python-ast.h * Modify asdl_c.py to enhance Python-ast.h: * Add #ifndef/#define Py_PYTHON_AST_H to be able to include the header twice * Add "extern { ... }" for C++ * Undefine "Yield" macro conflicting with winbase.h * Remove "#undef Yield" from C files, it's now done in Python-ast.h * Remove now useless includes in C files
1 parent fd3a91c commit 5f2df88

File tree

13 files changed

+42
-26
lines changed

13 files changed

+42
-26
lines changed

Include/Python-ast.h

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/ast.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
extern "C" {
55
#endif
66

7+
#include "Python-ast.h" /* mod_ty */
8+
#include "node.h" /* node */
9+
710
PyAPI_FUNC(int) PyAST_Validate(mod_ty);
811
PyAPI_FUNC(mod_ty) PyAST_FromNode(
912
const node *n,

Include/parsetok.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
21
/* Parser-tokenizer link interface */
2+
33
#ifndef Py_LIMITED_API
44
#ifndef Py_PARSETOK_H
55
#define Py_PARSETOK_H
66
#ifdef __cplusplus
77
extern "C" {
88
#endif
99

10+
#include "grammar.h" /* grammar */
11+
#include "node.h" /* node */
12+
1013
typedef struct {
1114
int error;
1215
#ifndef PGEN

Include/symtable.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#ifndef Py_LIMITED_API
22
#ifndef Py_SYMTABLE_H
33
#define Py_SYMTABLE_H
4-
54
#ifdef __cplusplus
65
extern "C" {
76
#endif
87

8+
#include "Python-ast.h" /* mod_ty */
9+
910
/* XXX(ncoghlan): This is a weird mix of public names and interpreter internal
1011
* names.
1112
*/
@@ -115,4 +116,4 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
115116
}
116117
#endif
117118
#endif /* !Py_SYMTABLE_H */
118-
#endif /* Py_LIMITED_API */
119+
#endif /* !Py_LIMITED_API */

Modules/parsermodule.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@
3232

3333
#include "Python.h" /* general Python API */
3434
#include "Python-ast.h" /* mod_ty */
35+
#include "ast.h"
3536
#include "graminit.h" /* symbols defined in the grammar */
3637
#include "node.h" /* internal parser structure */
3738
#include "errcode.h" /* error codes for PyNode_*() */
3839
#include "token.h" /* token definitions */
40+
/* ISTERMINAL() / ISNONTERMINAL() */
3941
#include "grammar.h"
4042
#include "parsetok.h"
41-
/* ISTERMINAL() / ISNONTERMINAL() */
42-
#undef Yield
43-
#include "ast.h"
4443

4544
extern grammar _PyParser_Grammar; /* From graminit.c */
4645

Parser/asdl_c.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,16 @@ def main(srcfile, dump_module=False):
12391239
if H_FILE:
12401240
with open(H_FILE, "w") as f:
12411241
f.write(auto_gen_msg)
1242-
f.write('#include "asdl.h"\n\n')
1242+
f.write('#ifndef Py_PYTHON_AST_H\n')
1243+
f.write('#define Py_PYTHON_AST_H\n')
1244+
f.write('#ifdef __cplusplus\n')
1245+
f.write('extern "C" {\n')
1246+
f.write('#endif\n')
1247+
f.write('\n')
1248+
f.write('#include "asdl.h"\n')
1249+
f.write('\n')
1250+
f.write('#undef Yield /* undefine macro conflicting with winbase.h */\n')
1251+
f.write('\n')
12431252
c = ChainOfVisitors(TypeDefVisitor(f),
12441253
StructVisitor(f),
12451254
PrototypeVisitor(f),
@@ -1248,6 +1257,11 @@ def main(srcfile, dump_module=False):
12481257
f.write("PyObject* PyAST_mod2obj(mod_ty t);\n")
12491258
f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n")
12501259
f.write("int PyAST_Check(PyObject* obj);\n")
1260+
f.write('\n')
1261+
f.write('#ifdef __cplusplus\n')
1262+
f.write('}\n')
1263+
f.write('#endif\n')
1264+
f.write('#endif /* !Py_PYTHON_AST_H */\n')
12511265

12521266
if C_FILE:
12531267
with open(C_FILE, "w") as f:

Python/ast_opt.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* AST Optimizer */
22
#include "Python.h"
33
#include "Python-ast.h"
4-
#include "node.h"
54
#include "ast.h"
65

76

Python/bltinmodule.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
/* Built-in functions */
22

33
#include "Python.h"
4-
#include "Python-ast.h"
5-
#include "pycore_state.h"
6-
7-
#include "node.h"
8-
#include "code.h"
9-
10-
#include "asdl.h"
11-
#include "ast.h"
12-
134
#include <ctype.h>
5+
#include "ast.h"
6+
#include "pycore_state.h"
147

158
_Py_IDENTIFIER(__builtins__);
169
_Py_IDENTIFIER(__dict__);

Python/compile.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "Python.h"
2525

2626
#include "Python-ast.h"
27-
#include "node.h"
2827
#include "ast.h"
2928
#include "code.h"
3029
#include "symtable.h"

Python/import.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "Python.h"
44

55
#include "Python-ast.h"
6-
#undef Yield /* undefine macro conflicting with winbase.h */
76
#include "pycore_hash.h"
87
#include "pycore_lifecycle.h"
98
#include "pycore_mem.h"

Python/pylifecycle.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "Python.h"
44

55
#include "Python-ast.h"
6-
#undef Yield /* undefine macro conflicting with winbase.h */
76
#include "pycore_context.h"
87
#include "pycore_hamt.h"
98
#include "pycore_lifecycle.h"

Python/pythonrun.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "Python.h"
1212

1313
#include "Python-ast.h"
14-
#undef Yield /* undefine macro conflicting with winbase.h */
1514
#include "pycore_state.h"
1615
#include "grammar.h"
1716
#include "node.h"

Python/symtable.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#include "Python.h"
22
#include "pycore_state.h"
3-
#ifdef Yield
4-
#undef Yield /* undefine conflicting macro from winbase.h */
5-
#endif
6-
#include "Python-ast.h"
7-
#include "code.h"
83
#include "symtable.h"
94
#include "structmember.h"
105

0 commit comments

Comments
 (0)