]> granicus.if.org Git - python/commitdiff
bpo-35177: Add dependencies between header files (GH-10361)
authorVictor Stinner <vstinner@redhat.com>
Sun, 11 Nov 2018 23:56:19 +0000 (00:56 +0100)
committerGitHub <noreply@github.com>
Sun, 11 Nov 2018 23:56:19 +0000 (00:56 +0100)
* 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

13 files changed:
Include/Python-ast.h
Include/ast.h
Include/parsetok.h
Include/symtable.h
Modules/parsermodule.c
Parser/asdl_c.py
Python/ast_opt.c
Python/bltinmodule.c
Python/compile.c
Python/import.c
Python/pylifecycle.c
Python/pythonrun.c
Python/symtable.c

index 2913d1d2d0a96b664c9a534e3189291c40d1ad21..1b7d9b10b1a567c7e6a4c9b1c711def67b630db8 100644 (file)
@@ -1,7 +1,15 @@
 /* File automatically generated by Parser/asdl_c.py. */
 
+#ifndef Py_PYTHON_AST_H
+#define Py_PYTHON_AST_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "asdl.h"
 
+#undef Yield /* undefine macro conflicting with winbase.h */
+
 typedef struct _mod *mod_ty;
 
 typedef struct _stmt *stmt_ty;
@@ -607,3 +615,8 @@ withitem_ty _Py_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena
 PyObject* PyAST_mod2obj(mod_ty t);
 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);
 int PyAST_Check(PyObject* obj);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_PYTHON_AST_H */
index c824554cf492615d115afe3963c8449e0addbb28..f1d734852eca79ffb0ebf213751461c8ec54d64d 100644 (file)
@@ -4,6 +4,9 @@
 extern "C" {
 #endif
 
+#include "Python-ast.h"   /* mod_ty */
+#include "node.h"         /* node */
+
 PyAPI_FUNC(int) PyAST_Validate(mod_ty);
 PyAPI_FUNC(mod_ty) PyAST_FromNode(
     const node *n,
index c9407a3f7020fe73549ec0e943307c652c505a4e..1217c46d0ed7b98dd2ecff05a26dc85afa830433 100644 (file)
@@ -1,5 +1,5 @@
-
 /* Parser-tokenizer link interface */
+
 #ifndef Py_LIMITED_API
 #ifndef Py_PARSETOK_H
 #define Py_PARSETOK_H
@@ -7,6 +7,9 @@
 extern "C" {
 #endif
 
+#include "grammar.h"      /* grammar */
+#include "node.h"         /* node */
+
 typedef struct {
     int error;
 #ifndef PGEN
index 007f88db40e7ebeb17e71d04a3b79c493139a002..949022bd6630aaad1219702fb56f6a3ec9c696f5 100644 (file)
@@ -1,11 +1,12 @@
 #ifndef Py_LIMITED_API
 #ifndef Py_SYMTABLE_H
 #define Py_SYMTABLE_H
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#include "Python-ast.h"   /* mod_ty */
+
 /* XXX(ncoghlan): This is a weird mix of public names and interpreter internal
  *                names.
  */
@@ -115,4 +116,4 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
 }
 #endif
 #endif /* !Py_SYMTABLE_H */
-#endif /* Py_LIMITED_API */
+#endif /* !Py_LIMITED_API */
index 38e5f750d5723d30742022db0a6ee1ea69d901f6..df239d67b2f72ca9547fdd461335fcd4bcdbba8d 100644 (file)
 
 #include "Python.h"                     /* general Python API             */
 #include "Python-ast.h"                 /* mod_ty */
+#include "ast.h"
 #include "graminit.h"                   /* symbols defined in the grammar */
 #include "node.h"                       /* internal parser structure      */
 #include "errcode.h"                    /* error codes for PyNode_*()     */
 #include "token.h"                      /* token definitions              */
+                                        /* ISTERMINAL() / ISNONTERMINAL() */
 #include "grammar.h"
 #include "parsetok.h"
-                                        /* ISTERMINAL() / ISNONTERMINAL() */
-#undef Yield
-#include "ast.h"
 
 extern grammar _PyParser_Grammar; /* From graminit.c */
 
index 4c280a96c30e7ef5177d932df7b0369b826ac6c0..6a8262c73b31d2799a4a6e5fde11af5a80eb0708 100644 (file)
@@ -1239,7 +1239,16 @@ def main(srcfile, dump_module=False):
     if H_FILE:
         with open(H_FILE, "w") as f:
             f.write(auto_gen_msg)
-            f.write('#include "asdl.h"\n\n')
+            f.write('#ifndef Py_PYTHON_AST_H\n')
+            f.write('#define Py_PYTHON_AST_H\n')
+            f.write('#ifdef __cplusplus\n')
+            f.write('extern "C" {\n')
+            f.write('#endif\n')
+            f.write('\n')
+            f.write('#include "asdl.h"\n')
+            f.write('\n')
+            f.write('#undef Yield /* undefine macro conflicting with winbase.h */\n')
+            f.write('\n')
             c = ChainOfVisitors(TypeDefVisitor(f),
                                 StructVisitor(f),
                                 PrototypeVisitor(f),
@@ -1248,6 +1257,11 @@ def main(srcfile, dump_module=False):
             f.write("PyObject* PyAST_mod2obj(mod_ty t);\n")
             f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n")
             f.write("int PyAST_Check(PyObject* obj);\n")
+            f.write('\n')
+            f.write('#ifdef __cplusplus\n')
+            f.write('}\n')
+            f.write('#endif\n')
+            f.write('#endif /* !Py_PYTHON_AST_H */\n')
 
     if C_FILE:
         with open(C_FILE, "w") as f:
index 1f9cb773ea7b958ba08d6216dd61e5b6cbed16de..6f72a7f63bf922f77a467d6f8450bdc9e22b7b09 100644 (file)
@@ -1,7 +1,6 @@
 /* AST Optimizer */
 #include "Python.h"
 #include "Python-ast.h"
-#include "node.h"
 #include "ast.h"
 
 
index 6c8672adfc1537c4299dfbe6c8fd75ec566e286a..6781589c29cffae80b8bf241f86e8b2f35ee0c2b 100644 (file)
@@ -1,16 +1,9 @@
 /* Built-in functions */
 
 #include "Python.h"
-#include "Python-ast.h"
-#include "pycore_state.h"
-
-#include "node.h"
-#include "code.h"
-
-#include "asdl.h"
-#include "ast.h"
-
 #include <ctype.h>
+#include "ast.h"
+#include "pycore_state.h"
 
 _Py_IDENTIFIER(__builtins__);
 _Py_IDENTIFIER(__dict__);
index 45a8c573a5fffc9b48a577237b381e9a5c6b060a..beceeea86b12d03c44921e328102d7a48c4c08a7 100644 (file)
@@ -24,7 +24,6 @@
 #include "Python.h"
 
 #include "Python-ast.h"
-#include "node.h"
 #include "ast.h"
 #include "code.h"
 #include "symtable.h"
index c0ea968fb8b09376637d4aaa4bb6976fa6ad8713..fcd88514eed5bf8009c93c16122a1fa15ada015f 100644 (file)
@@ -3,7 +3,6 @@
 #include "Python.h"
 
 #include "Python-ast.h"
-#undef Yield /* undefine macro conflicting with winbase.h */
 #include "pycore_hash.h"
 #include "pycore_lifecycle.h"
 #include "pycore_mem.h"
index 4c5cb53429172a6fe48f92a7b870cf4ccf2e366d..318d7cb4ba26324cbffeff906fc3452501b97882 100644 (file)
@@ -3,7 +3,6 @@
 #include "Python.h"
 
 #include "Python-ast.h"
-#undef Yield /* undefine macro conflicting with winbase.h */
 #include "pycore_context.h"
 #include "pycore_hamt.h"
 #include "pycore_lifecycle.h"
index 2f61aab40d9053533eb0ed0c49a7c98aa6fc6733..2b9f4f0415d65ec6e63ca00adc788aea30bbfa6e 100644 (file)
@@ -11,7 +11,6 @@
 #include "Python.h"
 
 #include "Python-ast.h"
-#undef Yield /* undefine macro conflicting with winbase.h */
 #include "pycore_state.h"
 #include "grammar.h"
 #include "node.h"
index 48e1515fa3bfe0fa399b5c0d4099147dea194942..40f91789c63c01228f461ba39b359020eef8df29 100644 (file)
@@ -1,10 +1,5 @@
 #include "Python.h"
 #include "pycore_state.h"
-#ifdef Yield
-#undef Yield /* undefine conflicting macro from winbase.h */
-#endif
-#include "Python-ast.h"
-#include "code.h"
 #include "symtable.h"
 #include "structmember.h"