gh-102416: Do not memoize incorrectly loop rules in the parser (#102467)

This commit is contained in:
Pablo Galindo Salgado 2023-03-06 14:41:53 +01:00 committed by GitHub
parent 6716254e71
commit f533f216e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 218 deletions

View File

@ -0,0 +1 @@
Do not memoize incorrectly automatically generated loop rules in the parser. Patch by Pablo Galindo.

216
Parser/parser.c generated

File diff suppressed because it is too large Load Diff

View File

@ -619,7 +619,8 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
self.add_return("_res") self.add_return("_res")
self.print("}") self.print("}")
self.print("int _mark = p->mark;") self.print("int _mark = p->mark;")
self.print("int _start_mark = p->mark;") if memoize:
self.print("int _start_mark = p->mark;")
self.print("void **_children = PyMem_Malloc(sizeof(void *));") self.print("void **_children = PyMem_Malloc(sizeof(void *));")
self.out_of_memory_return(f"!_children") self.out_of_memory_return(f"!_children")
self.print("Py_ssize_t _children_capacity = 1;") self.print("Py_ssize_t _children_capacity = 1;")
@ -642,7 +643,7 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
self.out_of_memory_return(f"!_seq", cleanup_code="PyMem_Free(_children);") self.out_of_memory_return(f"!_seq", cleanup_code="PyMem_Free(_children);")
self.print("for (int i = 0; i < _n; i++) asdl_seq_SET_UNTYPED(_seq, i, _children[i]);") self.print("for (int i = 0; i < _n; i++) asdl_seq_SET_UNTYPED(_seq, i, _children[i]);")
self.print("PyMem_Free(_children);") self.print("PyMem_Free(_children);")
if node.name: if memoize and node.name:
self.print(f"_PyPegen_insert_memo(p, _start_mark, {node.name}_type, _seq);") self.print(f"_PyPegen_insert_memo(p, _start_mark, {node.name}_type, _seq);")
self.add_return("_seq") self.add_return("_seq")