diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-03-06 13:41:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-06 13:41:53 (GMT) |
commit | f533f216e6aaba3f36639ae27210420e7dcf9de1 (patch) | |
tree | 51aff44a0212cd31befe11f5b9ac3d2ecc7d6a8b /Tools/peg_generator | |
parent | 6716254e71eeb4666fd6d1a13857832caad7b19f (diff) | |
download | cpython-f533f216e6aaba3f36639ae27210420e7dcf9de1.zip cpython-f533f216e6aaba3f36639ae27210420e7dcf9de1.tar.gz cpython-f533f216e6aaba3f36639ae27210420e7dcf9de1.tar.bz2 |
gh-102416: Do not memoize incorrectly loop rules in the parser (#102467)
Diffstat (limited to 'Tools/peg_generator')
-rw-r--r-- | Tools/peg_generator/pegen/c_generator.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py index c41d87b..e72ce7a 100644 --- a/Tools/peg_generator/pegen/c_generator.py +++ b/Tools/peg_generator/pegen/c_generator.py @@ -619,7 +619,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;") @@ -642,7 +643,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") |