[PATCH] Fix segmentation fault on parsing empty list-assignments
This same patch is on bitbucket at https://bitbucket.org/price/pypy, where I've sent a pull request. Holger Krekel suggested on IRC that I send mail here. If others have different preferences for how to submit a patch, let me know. Before this patch, "[] = []" would abort the interpreter, with a segmentation fault if in pypy-c. A segmentation fault is always bad, but in this case further the code is valid Python, if not very useful. (In my commit message on bitbucket, I incorrectly said it only affects invalid Python, like "[] += []".) Greg diff -r eb44d135f334 -r 0db4ac049ea2 pypy/interpreter/astcompiler/asthelpers.py --- a/pypy/interpreter/astcompiler/asthelpers.py Tue Mar 08 11:14:36 2011 -0800 +++ b/pypy/interpreter/astcompiler/asthelpers.py Wed Mar 09 03:26:54 2011 -0800 @@ -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): diff -r eb44d135f334 -r 0db4ac049ea2 pypy/interpreter/astcompiler/test/test_compiler.py --- a/pypy/interpreter/astcompiler/test/test_compiler.py Tue Mar 08 11:14:36 2011 -0800 +++ b/pypy/interpreter/astcompiler/test/test_compiler.py Wed Mar 09 03:26:54 2011 -0800 @@ -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)
On 09/03/11 13:29, Greg Price wrote:
This same patch is on bitbucket at https://bitbucket.org/price/pypy, where I've sent a pull request. Holger Krekel suggested on IRC that I send mail here. If others have different preferences for how to submit a patch, let me know.
Hi Greg, I have pushed your commit upstream, thanks for help! ciao, anto
participants (2)
-
Antonio Cuni
-
Greg Price