]> granicus.if.org Git - python/commitdiff
Issue 1881. Increased the stack limit from 500 to 1500. Also added
authorFacundo Batista <facundobatista@gmail.com>
Sat, 23 Feb 2008 12:01:13 +0000 (12:01 +0000)
committerFacundo Batista <facundobatista@gmail.com>
Sat, 23 Feb 2008 12:01:13 +0000 (12:01 +0000)
a test for this (and because of this test you'll see in stderr a
message that parser.c sends before raising MemoryError).
Thanks Ralf Schmitt.

Lib/test/test_parser.py
Misc/NEWS
Parser/parser.h

index fd2861034d672cc473f124127cedc1be710d8fec..411911211a3e9bbcf5b03998cc4319290746ad0a 100644 (file)
@@ -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,
     )
 
 
index 2921cb2af95f6ba6f68ded9406733b378bbcdd11..a33bf714c45f203c2912333ee4648e8850c61893 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,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.
+
 - Added the future_builtins module, which contains hex() and oct().
   These are the PEP 3127 version of these functions, designed to be
   compatible with the hex() and oct() builtins from Python 3.0.  They
index bdca3e9440a05702e924b8916cfe58bb054cc189..403236d1ea2b87cdedea2003df3f1e8a7bb0e7a9 100644 (file)
@@ -7,7 +7,7 @@ extern "C" {
 
 /* Parser interface */
 
-#define MAXSTACK 500
+#define MAXSTACK 1500
 
 typedef struct {
        int              s_state;       /* State in current DFA */