https://github.com/python/cpython/commit/89df01bd2718fb43f2dd1f884381cb9f2a7cf289
commit: 89df01bd2718fb43f2dd1f884381cb9f2a7cf289
branch: 3.14
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: vstinner <vstin...@python.org>
date: 2025-06-03T12:23:06Z
summary:

[3.14] gh-135028: Increase parser MAXSTACK for nested parenthesis (GH-135031) 
(#135059)

gh-135028: Increase parser MAXSTACK for nested parenthesis (GH-135031)
(cherry picked from commit 6e80f11eb5eba360334b4ace105eb7d73394baf7)

Co-authored-by: Victor Stinner <vstin...@python.org>

files:
M Lib/test/test_grammar.py
M Parser/parser.c
M Tools/peg_generator/pegen/c_generator.py

diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index c39565144bf7f4..7f5d48b9c63ab7 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -1,7 +1,7 @@
 # Python test set -- part 1, grammar.
 # This just tests whether the parser accepts them all.
 
-from test.support import check_syntax_error
+from test.support import check_syntax_error, skip_wasi_stack_overflow
 from test.support import import_helper
 import annotationlib
 import inspect
@@ -249,6 +249,18 @@ def test_eof_error(self):
                 compile(s, "<test>", "exec")
             self.assertIn("was never closed", str(cm.exception))
 
+    @skip_wasi_stack_overflow()
+    def test_max_level(self):
+        # Macro defined in Parser/lexer/state.h
+        MAXLEVEL = 200
+
+        result = eval("(" * MAXLEVEL + ")" * MAXLEVEL)
+        self.assertEqual(result, ())
+
+        with self.assertRaises(SyntaxError) as cm:
+            eval("(" * (MAXLEVEL + 1) + ")" * (MAXLEVEL + 1))
+        self.assertStartsWith(str(cm.exception), 'too many nested parentheses')
+
 var_annot_global: int # a global annotated is necessary for test_var_annot
 
 
diff --git a/Parser/parser.c b/Parser/parser.c
index dc55e391d29280..5755f16a65c5ca 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -14,7 +14,7 @@
 #    define MAXSTACK 4000
 #  endif
 #else
-#  define MAXSTACK 4000
+#  define MAXSTACK 6000
 #endif
 static const int n_keyword_lists = 9;
 static KeywordToken *reserved_keywords[] = {
diff --git a/Tools/peg_generator/pegen/c_generator.py 
b/Tools/peg_generator/pegen/c_generator.py
index 2be85a163b4043..09c5651f24a3bb 100644
--- a/Tools/peg_generator/pegen/c_generator.py
+++ b/Tools/peg_generator/pegen/c_generator.py
@@ -44,7 +44,7 @@
 #    define MAXSTACK 4000
 #  endif
 #else
-#  define MAXSTACK 4000
+#  define MAXSTACK 6000
 #endif
 
 """

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to