Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r96365:f8035bf26e3d Date: 2019-03-27 15:48 +0100 http://bitbucket.org/pypy/pypy/changeset/f8035bf26e3d/
Log: Test and fix for a large list unpacking diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py --- a/pypy/interpreter/astcompiler/codegen.py +++ b/pypy/interpreter/astcompiler/codegen.py @@ -921,7 +921,7 @@ elt_count = len(l.elts) if l.elts is not None else 0 if l.ctx == ast.Store: self.emit_op_arg(ops.UNPACK_SEQUENCE, elt_count) - if elt_count > MAX_STACKDEPTH_CONTAINERS: + if elt_count > MAX_STACKDEPTH_CONTAINERS and l.ctx == ast.Load: # pushing all the elements would make the stack depth gigantic. # build the list incrementally instead self.emit_op_arg(ops.BUILD_LIST, 0) 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 @@ -1229,6 +1229,17 @@ code.exec_code(space, w_dict, w_dict) assert space.unwrap(space.getitem(w_dict, space.newtext("a"))) == range(200) + def test_list_unpacking(self): + space = self.space + source = "[" + ",".join(['b%d' % i for i in range(200)]) + "] = a\n" + code = compile_with_astcompiler(source, 'exec', space) + assert code.co_stacksize == 200 # xxx remains big + w_dict = space.newdict() + space.setitem(w_dict, space.newtext("a"), space.wrap(range(42, 242))) + code.exec_code(space, w_dict, w_dict) + assert space.unwrap(space.getitem(w_dict, space.newtext("b0"))) == 42 + assert space.unwrap(space.getitem(w_dict, space.newtext("b199"))) == 241 + def test_set(self): space = self.space source = "a = {" + ",".join([str(i) for i in range(200)]) + "}\n" _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit