summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-03-18 01:46:06 (GMT)
committerGitHub <noreply@github.com>2021-03-18 01:46:06 (GMT)
commite0bf70d08c4a4a68782702e747e6bf7670667591 (patch)
tree36994e29ed642e690b7932129ee150c484fd20d9 /Parser
parent08fb8ac99ab03d767aa0f1cfab3573eddf9df018 (diff)
downloadcpython-e0bf70d08c4a4a68782702e747e6bf7670667591.zip
cpython-e0bf70d08c4a4a68782702e747e6bf7670667591.tar.gz
cpython-e0bf70d08c4a4a68782702e747e6bf7670667591.tar.bz2
bpo-43244: Fix test_peg_generator for PyAST_Validate() (GH-24912)
test_peg_generator now defines _Py_TEST_PEGEN macro when building C code to not call PyAST_Validate() in Parser/pegen.c. Moreover, it defines Py_BUILD_CORE_MODULE macro to get access to the internal C API. Remove "global_ast_state" from Python-ast.c when it's built by test_peg_generator: always get the AST state from the current interpreter.
Diffstat (limited to 'Parser')
-rwxr-xr-xParser/asdl_c.py34
-rw-r--r--Parser/pegen.c3
2 files changed, 6 insertions, 31 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index e96f1f3..aefea12 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -1373,17 +1373,13 @@ def generate_ast_fini(module_state, f):
f.write(textwrap.dedent("""
void _PyAST_Fini(PyInterpreterState *interp)
{
- #ifdef Py_BUILD_CORE
struct ast_state *state = &interp->ast;
- #else
- struct ast_state *state = &global_ast_state;
- #endif
"""))
for s in module_state:
f.write(" Py_CLEAR(state->" + s + ');\n')
f.write(textwrap.dedent("""
- #if defined(Py_BUILD_CORE) && !defined(NDEBUG)
+ #if !defined(NDEBUG)
state->initialized = -1;
#else
state->initialized = 0;
@@ -1428,24 +1424,15 @@ def generate_module_def(mod, f, internal_h):
generate_ast_state(module_state, internal_h)
print(textwrap.dedent(f"""
- #ifdef Py_BUILD_CORE
- # include "pycore_ast_state.h" // struct ast_state
- # include "pycore_interp.h" // _PyInterpreterState.ast
- # include "pycore_pystate.h" // _PyInterpreterState_GET()
- #else
- """).strip(), file=f)
-
- generate_ast_state(module_state, f)
-
- print(textwrap.dedent(f"""
- #endif // Py_BUILD_CORE
+ #include "pycore_ast_state.h" // struct ast_state
+ #include "pycore_interp.h" // _PyInterpreterState.ast
+ #include "pycore_pystate.h" // _PyInterpreterState_GET()
""").rstrip(), file=f)
f.write("""
// Forward declaration
static int init_types(struct ast_state *state);
-#ifdef Py_BUILD_CORE
static struct ast_state*
get_ast_state(void)
{
@@ -1456,19 +1443,6 @@ get_ast_state(void)
}
return state;
}
-#else
-static struct ast_state global_ast_state;
-
-static struct ast_state*
-get_ast_state(void)
-{
- struct ast_state *state = &global_ast_state;
- if (!init_types(state)) {
- return NULL;
- }
- return state;
-}
-#endif // Py_BUILD_CORE
""")
# f-string for {mod.name}
diff --git a/Parser/pegen.c b/Parser/pegen.c
index 3011993..84bdf8d 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -1265,7 +1265,8 @@ _PyPegen_run_parser(Parser *p)
return RAISE_SYNTAX_ERROR("multiple statements found while compiling a single statement");
}
-#if defined(Py_DEBUG) && defined(Py_BUILD_CORE)
+ // test_peg_generator defines _Py_TEST_PEGEN to not call PyAST_Validate()
+#if defined(Py_DEBUG) && !defined(_Py_TEST_PEGEN)
if (p->start_rule == Py_single_input ||
p->start_rule == Py_file_input ||
p->start_rule == Py_eval_input)