diff --git a/Include/Python-ast.h b/Include/Python-ast.h index 2913d1d2d0a96b..228e13522ec909 100644 --- a/Include/Python-ast.h +++ b/Include/Python-ast.h @@ -1,7 +1,15 @@ /* File automatically generated by Parser/asdl_c.py. */ +#ifndef PYTHON_AST_H +#define 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 /* !PYTHON_AST_H */ diff --git a/Include/ast.h b/Include/ast.h index c824554cf49261..7a57533eab58d7 100644 --- a/Include/ast.h +++ b/Include/ast.h @@ -4,6 +4,9 @@ extern "C" { #endif +#include "node.h" /* node */ +#include "Python-ast.h" /* mod_ty */ + PyAPI_FUNC(int) PyAST_Validate(mod_ty); PyAPI_FUNC(mod_ty) PyAST_FromNode( const node *n, diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index 38e5f750d5723d..b13c2e0b9f2eb5 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -39,7 +39,6 @@ #include "grammar.h" #include "parsetok.h" /* ISTERMINAL() / ISNONTERMINAL() */ -#undef Yield #include "ast.h" extern grammar _PyParser_Grammar; /* From graminit.c */ diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 4c280a96c30e7e..2a29beb41ab0e6 100644 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -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 PYTHON_AST_H\n') + f.write('#define 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 /* !PYTHON_AST_H */\n') if C_FILE: with open(C_FILE, "w") as f: diff --git a/Python/import.c b/Python/import.c index 67911ff0e41b6d..13bde8f7aac40e 100644 --- a/Python/import.c +++ b/Python/import.c @@ -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" diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 4c5cb53429172a..318d7cb4ba2632 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -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" diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 2f61aab40d9053..2b9f4f0415d65e 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -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" diff --git a/Python/symtable.c b/Python/symtable.c index 48e1515fa3bfe0..cd18ef5b0278a1 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -1,8 +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"