Issue 1881. Increased the stack limit from 500 to 1500. Also added

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.
This commit is contained in:
Facundo Batista 2008-02-23 12:01:13 +00:00
parent 7832d4d534
commit fc2d01032f
3 changed files with 21 additions and 1 deletions

View File

@ -480,11 +480,28 @@ class CompileTestCase(unittest.TestCase):
st = parser.suite('a = u"\u1"') st = parser.suite('a = u"\u1"')
self.assertRaises(SyntaxError, parser.compilest, st) 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(): def test_main():
test_support.run_unittest( test_support.run_unittest(
RoundtripLegalSyntaxTestCase, RoundtripLegalSyntaxTestCase,
IllegalSyntaxTestCase, IllegalSyntaxTestCase,
CompileTestCase, CompileTestCase,
ParserStackLimitTestCase,
) )

View File

@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1?
Core and builtins 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(). - Added the future_builtins module, which contains hex() and oct().
These are the PEP 3127 version of these functions, designed to be These are the PEP 3127 version of these functions, designed to be
compatible with the hex() and oct() builtins from Python 3.0. They compatible with the hex() and oct() builtins from Python 3.0. They

View File

@ -7,7 +7,7 @@ extern "C" {
/* Parser interface */ /* Parser interface */
#define MAXSTACK 500 #define MAXSTACK 1500
typedef struct { typedef struct {
int s_state; /* State in current DFA */ int s_state; /* State in current DFA */