[pypy-svn] pypy default: fix segmentation fault on parsing some invalid Python

Greg Price commits-noreply at bitbucket.org
Wed Mar 9 14:58:07 CET 2011


Author: Greg Price <greg at quora.com>
Branch: 
Changeset: r42485:0db4ac049ea2
Date: 2011-03-09 03:26 -0800
http://bitbucket.org/pypy/pypy/changeset/0db4ac049ea2/

Log:	fix segmentation fault on parsing some invalid Python

diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -70,6 +70,9 @@
 
     st = simple_test
 
+    def error_test(self, source, exc_type):
+        py.test.raises(exc_type, self.simple_test, source, None, None)
+
     def test_long_jump(self):
         func = """def f(x):
     y = 0
@@ -98,11 +101,13 @@
         self.simple_test(stmt, "type(x)", int)
 
     def test_tuple_assign(self):
+        yield self.error_test, "() = 1", SyntaxError
         yield self.simple_test, "x,= 1,", "x", 1
         yield self.simple_test, "x,y = 1,2", "x,y", (1, 2)
         yield self.simple_test, "x,y,z = 1,2,3", "x,y,z", (1, 2, 3)
         yield self.simple_test, "x,y,z,t = 1,2,3,4", "x,y,z,t", (1, 2, 3, 4)
         yield self.simple_test, "x,y,x,t = 1,2,3,4", "x,y,t", (3, 2, 4)
+        yield self.simple_test, "[] = []", "1", 1
         yield self.simple_test, "[x]= 1,", "x", 1
         yield self.simple_test, "[x,y] = [1,2]", "x,y", (1, 2)
         yield self.simple_test, "[x,y,z] = 1,2,3", "x,y,z", (1, 2, 3)

diff --git a/pypy/interpreter/astcompiler/asthelpers.py b/pypy/interpreter/astcompiler/asthelpers.py
--- a/pypy/interpreter/astcompiler/asthelpers.py
+++ b/pypy/interpreter/astcompiler/asthelpers.py
@@ -40,9 +40,10 @@
         return self.elts
 
     def set_context(self, ctx):
-        for elt in self.elts:
-            elt.set_context(ctx)
-        self.ctx = ctx
+        if self.elts:
+            for elt in self.elts:
+                elt.set_context(ctx)
+            self.ctx = ctx
 
 
 class __extend__(ast.Attribute):


More information about the Pypy-commit mailing list