Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Normalize AST arguments construction to always allocate
kwonlyargs/kw_defaults (with length parity) and assert the invariant.
16 changes: 16 additions & 0 deletions Parser/asdl_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,22 @@ def emit(s, depth=0, reflow=True):
emit("p = (%s)_PyArena_Malloc(arena, sizeof(*p));" % ctype, 1);
emit("if (!p)", 1)
emit("return NULL;", 2)
# Special-case normalization for the arguments product to guarantee
# non-NULL kwonlyargs/kw_defaults with matched lengths.
if name == "arguments":
emit("if (kwonlyargs == NULL) {", 1)
emit("kwonlyargs = _Py_asdl_arg_seq_new(0, arena);", 2)
emit("if (!kwonlyargs) {", 2)
emit("return NULL;", 3)
emit("}", 2)
emit("}", 1)
emit("if (kw_defaults == NULL) {", 1)
emit("kw_defaults = _Py_asdl_expr_seq_new(asdl_seq_LEN(kwonlyargs), arena);", 2)
emit("if (!kw_defaults) {", 2)
emit("return NULL;", 3)
emit("}", 2)
emit("}", 1)
emit("assert(asdl_seq_LEN(kw_defaults) == asdl_seq_LEN(kwonlyargs));", 1)
if union:
self.emit_body_union(name, args, attrs)
else:
Expand Down
13 changes: 13 additions & 0 deletions Python/Python-ast.c

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

Loading