FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-43244: test_peg_generator defines _Py_TEST_PEGEN macro by vstinner · Pull Request #24912 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (2) .py  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
34 changes: 4 additions & 30 deletions Parser/asdl_c.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -1456,19 +1443,6 @@ def generate_module_def(mod, f, internal_h):
}
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}
Expand Down
3 changes: 2 additions & 1 deletion Parser/pegen.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
256 changes: 5 additions & 251 deletions Python/Python-ast.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Tools/peg_generator/pegen/build.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def compile_c_extension(
source_file_path = pathlib.Path(generated_source_path)
extension_name = source_file_path.stem
extra_compile_args = get_extra_flags("CFLAGS", "PY_CFLAGS_NODIST")
extra_compile_args.append("-DPy_BUILD_CORE_MODULE")
# Define _Py_TEST_PEGEN to not call PyAST_Validate() in Parser/pegen.c
extra_compile_args.append('-D_Py_TEST_PEGEN')
extra_link_args = get_extra_flags("LDFLAGS", "PY_LDFLAGS_NODIST")
if keep_asserts:
extra_compile_args.append("-UNDEBUG")
Expand Down

Back | FazBrowse Home | New Git URL