[pypy-svn] r56356 - in pypy/dist/pypy/module/recparser: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Jul 7 17:30:49 CEST 2008


Author: cfbolz
Date: Mon Jul  7 17:30:47 2008
New Revision: 56356

Modified:
   pypy/dist/pypy/module/recparser/pyparser.py
   pypy/dist/pypy/module/recparser/test/test_parser.py
Log:
Fix a segfault (IndexError) in the recparser.


Modified: pypy/dist/pypy/module/recparser/pyparser.py
==============================================================================
--- pypy/dist/pypy/module/recparser/pyparser.py	(original)
+++ pypy/dist/pypy/module/recparser/pyparser.py	Mon Jul  7 17:30:47 2008
@@ -149,6 +149,10 @@
     totuple = interp2app(STType.descr_totuple),
 )
 
+def get(space, name):
+    w_module = space.getbuiltinmodule('parser')
+    return space.getattr(w_module, space.wrap(name))
+
 def get_ast_compiler(space):
     from pypy.interpreter.pycompiler import PythonAstCompiler
     compiler = space.createcompiler()
@@ -189,10 +193,15 @@
 
 ast2tuple.unwrap_spec = [ObjSpace, STType, int]
 
+def check_length(space, items, length):
+    if len(items) < length:
+        raise OperationError(get(space, "ParserError"),
+                             space.wrap("argument too small"))
 
 def unwrap_syntax_tree( space, w_sequence ):
     items = space.unpackiterable( w_sequence )
     parser = space.default_compiler.parser
+    check_length(space, items, 1)
     nodetype = space.int_w( items[0] )
     if parser.is_base_token(nodetype):
         nodes = []

Modified: pypy/dist/pypy/module/recparser/test/test_parser.py
==============================================================================
--- pypy/dist/pypy/module/recparser/test/test_parser.py	(original)
+++ pypy/dist/pypy/module/recparser/test/test_parser.py	Mon Jul  7 17:30:47 2008
@@ -20,3 +20,11 @@
         import parser
         parser.suite("a = 3").totuple()
 
+class AppTestRecparserErrors: 
+    def setup_class(cls):
+        cls.space = space
+
+    def test_sequence2st_bug1(self):
+        import parser
+        raises(parser.ParserError, parser.sequence2st, ())
+



More information about the Pypy-commit mailing list