diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -480,11 +480,28 @@ class CompileTestCase(unittest.TestCase) st = parser.suite('a = u"\u1"') self.assertRaises(SyntaxError, parser.compilest, st) +class ParserStackLimitTestCase(unittest.TestCase): + """try to push the parser to/over it's limits. + see http://bugs.python.org/issue1881 for a discussion + """ + def _nested_expression(self, level): + return "["*level+"]"*level + + def test_deeply_nested_list(self): + e = self._nested_expression(99) + st = parser.expr(e) + st.compile() + + def test_trigger_memory_error(self): + e = self._nested_expression(100) + self.assertRaises(MemoryError, parser.expr, e) + def test_main(): test_support.run_unittest( RoundtripLegalSyntaxTestCase, IllegalSyntaxTestCase, CompileTestCase, + ParserStackLimitTestCase, ) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -11,6 +11,9 @@ What's New in Python 2.6 alpha 1? Core and builtins ----------------- + +- Issue #1881: An internal parser limit has been increased. Also see + issue 215555 for a discussion. - Patch #1720595: add T_BOOL to the range of structmember types. diff --git a/Parser/parser.h b/Parser/parser.h --- a/Parser/parser.h +++ b/Parser/parser.h @@ -7,7 +7,7 @@ extern "C" { /* Parser interface */ -#define MAXSTACK 500 +#define MAXSTACK 1500 typedef struct { int s_state; /* State in current DFA */