diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-01-03 19:54:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-03 19:54:06 (GMT) |
commit | dd6c35761a4cd417e126a2d51dd0b89c8a30e5de (patch) | |
tree | ae428b310505891619b4a6a0e65f7aca7db7ada1 /Tools | |
parent | 9d6a239a34a66e16188d76c23a3a770515ca44ca (diff) | |
download | cpython-dd6c35761a4cd417e126a2d51dd0b89c8a30e5de.zip cpython-dd6c35761a4cd417e126a2d51dd0b89c8a30e5de.tar.gz cpython-dd6c35761a4cd417e126a2d51dd0b89c8a30e5de.tar.bz2 |
bpo-46110: Restore commit e9898bf153d26059261ffef11f7643ae991e2a4c
This restores commit e9898bf153d26059261ffef11f7643ae991e2a4c .
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/peg_generator/pegen/c_generator.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py index 9cfbf38..ee255c8 100644 --- a/Tools/peg_generator/pegen/c_generator.py +++ b/Tools/peg_generator/pegen/c_generator.py @@ -37,6 +37,8 @@ EXTENSION_PREFIX = """\ # define D(x) #endif +# define MAXSTACK 6000 + """ @@ -364,10 +366,14 @@ class CParserGenerator(ParserGenerator, GrammarVisitor): self.skip_actions = skip_actions def add_level(self) -> None: - self.print("D(p->level++);") + self.print("if (p->level++ == MAXSTACK) {") + with self.indent(): + self.print("p->error_indicator = 1;") + self.print("PyErr_NoMemory();") + self.print("}") def remove_level(self) -> None: - self.print("D(p->level--);") + self.print("p->level--;") def add_return(self, ret_val: str) -> None: self.remove_level() @@ -544,9 +550,10 @@ class CParserGenerator(ParserGenerator, GrammarVisitor): self.print("p->in_raw_rule++;") self.print(f"void *_raw = {node.name}_raw(p);") self.print("p->in_raw_rule--;") - self.print("if (p->error_indicator)") + self.print("if (p->error_indicator) {") with self.indent(): - self.print("return NULL;") + self.add_return("NULL") + self.print("}") self.print("if (_raw == NULL || p->mark <= _resmark)") with self.indent(): self.print("break;") |