Skip to content

Commit 70856f1

Browse files
committed
asdl: use _PyOnceFlag in Python-ast.c
1 parent 212fef4 commit 70856f1

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Include/internal/pycore_ast_state.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Parser/asdl_c.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,7 @@ def visit(self, object):
14671467
def generate_ast_state(module_state, f):
14681468
f.write('struct ast_state {\n')
14691469
f.write(' int initialized;\n')
1470+
f.write(' _PyOnceFlag once;\n')
14701471
f.write(' int recursion_depth;\n')
14711472
f.write(' int recursion_limit;\n')
14721473
for s in module_state:
@@ -1544,8 +1545,12 @@ def generate_module_def(mod, metadata, f, internal_h):
15441545
{
15451546
PyInterpreterState *interp = _PyInterpreterState_GET();
15461547
struct ast_state *state = &interp->ast;
1547-
if (!init_types(state)) {
1548-
return NULL;
1548+
if (_PyBeginOnce(&state->once)) {
1549+
if (!init_types(state)) {
1550+
_PyEndOnceFailed(&state->once);
1551+
return NULL;
1552+
}
1553+
_PyEndOnce(&state->once);
15491554
}
15501555
return state;
15511556
}

Python/Python-ast.c

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)