[3.10] gh-102416: Do not memoize incorrectly loop rules in the parser (GH-102467). (#102474)

This commit is contained in:
Pablo Galindo Salgado 2023-03-06 17:59:16 +01:00 committed by GitHub
parent f5280e2ed8
commit 6b49cc64a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 178 deletions

View file

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

File diff suppressed because it is too large Load diff

View file

@ -604,7 +604,8 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
self.add_return("_res")
self.print("}")
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.out_of_memory_return(f"!_children")
self.print("Py_ssize_t _children_capacity = 1;")
@ -624,7 +625,7 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
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("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.add_return("_seq")