Skip to content

Commit

Permalink
asdl: use _PyOnceFlag in Python-ast.c
Browse files Browse the repository at this point in the history
  • Loading branch information
colesbury committed Apr 23, 2023
1 parent 212fef4 commit 70856f1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions Include/internal/pycore_ast_state.h

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

9 changes: 7 additions & 2 deletions Parser/asdl_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,7 @@ def visit(self, object):
def generate_ast_state(module_state, f):
f.write('struct ast_state {\n')
f.write(' int initialized;\n')
f.write(' _PyOnceFlag once;\n')
f.write(' int recursion_depth;\n')
f.write(' int recursion_limit;\n')
for s in module_state:
Expand Down Expand Up @@ -1544,8 +1545,12 @@ def generate_module_def(mod, metadata, f, internal_h):
{
PyInterpreterState *interp = _PyInterpreterState_GET();
struct ast_state *state = &interp->ast;
if (!init_types(state)) {
return NULL;
if (_PyBeginOnce(&state->once)) {
if (!init_types(state)) {
_PyEndOnceFailed(&state->once);
return NULL;
}
_PyEndOnce(&state->once);
}
return state;
}
Expand Down
8 changes: 6 additions & 2 deletions Python/Python-ast.c

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

0 comments on commit 70856f1

Please sign in to comment.