Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 4 additions & 30 deletions 34 Parser/asdl_c.py
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 3 Parser/pegen.c
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 256 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 3 Tools/peg_generator/pegen/build.py
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.