Skip to content

Commit 89df01b

Browse files
[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 6e80f11) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 9e0ac76 commit 89df01b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Lib/test/test_grammar.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Python test set -- part 1, grammar.
22
# This just tests whether the parser accepts them all.
33

4-
from test.support import check_syntax_error
4+
from test.support import check_syntax_error, skip_wasi_stack_overflow
55
from test.support import import_helper
66
import annotationlib
77
import inspect
@@ -249,6 +249,18 @@ def test_eof_error(self):
249249
compile(s, "<test>", "exec")
250250
self.assertIn("was never closed", str(cm.exception))
251251

252+
@skip_wasi_stack_overflow()
253+
def test_max_level(self):
254+
# Macro defined in Parser/lexer/state.h
255+
MAXLEVEL = 200
256+
257+
result = eval("(" * MAXLEVEL + ")" * MAXLEVEL)
258+
self.assertEqual(result, ())
259+
260+
with self.assertRaises(SyntaxError) as cm:
261+
eval("(" * (MAXLEVEL + 1) + ")" * (MAXLEVEL + 1))
262+
self.assertStartsWith(str(cm.exception), 'too many nested parentheses')
263+
252264
var_annot_global: int # a global annotated is necessary for test_var_annot
253265

254266

Parser/parser.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/peg_generator/pegen/c_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
# define MAXSTACK 4000
4545
# endif
4646
#else
47-
# define MAXSTACK 4000
47+
# define MAXSTACK 6000
4848
#endif
4949
5050
"""

0 commit comments

Comments
 (0)