Author: Maciej Fijalkowski <fij...@gmail.com> Branch: Changeset: r53702:426fcfc2962a Date: 2012-03-15 20:28 +0100 http://bitbucket.org/pypy/pypy/changeset/426fcfc2962a/
Log: merge diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py --- a/pypy/interpreter/error.py +++ b/pypy/interpreter/error.py @@ -47,6 +47,11 @@ def async(self, space): "Check if this is an exception that should better not be caught." + if not space.full_exceptions: + # flow objspace does not support such exceptions and more + # importantly, raises KeyboardInterrupt if you try to access + # space.w_KeyboardInterrupt + return False return (self.match(space, space.w_SystemExit) or self.match(space, space.w_KeyboardInterrupt)) diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py --- a/pypy/objspace/flow/objspace.py +++ b/pypy/objspace/flow/objspace.py @@ -117,7 +117,7 @@ else: return Constant(tuple(content)) - def newlist(self, args_w): + def newlist(self, args_w, sizehint=None): if self.concrete_mode: content = [self.unwrap(w_arg) for w_arg in args_w] return Constant(content) diff --git a/pypy/objspace/flow/test/test_objspace.py b/pypy/objspace/flow/test/test_objspace.py --- a/pypy/objspace/flow/test/test_objspace.py +++ b/pypy/objspace/flow/test/test_objspace.py @@ -849,16 +849,25 @@ c.co_filename, c.co_name, c.co_firstlineno, c.co_lnotab) + def patch_opcodes(self, *opcodes): + flow_meth_names = flowcontext.FlowSpaceFrame.opcode_method_names + pyframe_meth_names = PyFrame.opcode_method_names + for name in opcodes: + num = bytecode_spec.opmap[name] + setattr(self, 'old_' + name, flow_meth_names[num]) + flow_meth_names[num] = pyframe_meth_names[num] + + def unpatch_opcodes(self, *opcodes): + flow_meth_names = flowcontext.FlowSpaceFrame.opcode_method_names + for name in opcodes: + num = bytecode_spec.opmap[name] + flow_meth_names[num] = getattr(self, 'old_' + name) + def test_callmethod_opcode(self): """ Tests code generated by pypy-c compiled with CALL_METHOD bytecode """ - flow_meth_names = flowcontext.FlowSpaceFrame.opcode_method_names - pyframe_meth_names = PyFrame.opcode_method_names - for name in ['CALL_METHOD', 'LOOKUP_METHOD']: - num = bytecode_spec.opmap[name] - locals()['old_' + name] = flow_meth_names[num] - flow_meth_names[num] = pyframe_meth_names[num] + self.patch_opcodes('CALL_METHOD', 'LOOKUP_METHOD') try: class X: def m(self): @@ -878,9 +887,29 @@ assert all_ops['simple_call'] == 2 assert all_ops['getattr'] == 1 finally: - for name in ['CALL_METHOD', 'LOOKUP_METHOD']: - num = bytecode_spec.opmap[name] - flow_meth_names[num] = locals()['old_' + name] + self.unpatch_opcodes('CALL_METHOD', 'LOOKUP_METHOD') + + def test_build_list_from_arg_opcode(self): + """ Tests code generated by pypy-c compiled with BUILD_LIST_FROM_ARG + bytecode + """ + self.patch_opcodes('BUILD_LIST_FROM_ARG') + try: + def f(): + return [i for i in "abc"] + + # this code is generated by pypy-c when compiling above f + pypy_code = 'd\x01\x00\xcb\x00\x00D]\x0c\x00}\x00\x00|\x00\x00^\x02\x00q\x07\x00S' + new_c = self.monkey_patch_code(f.func_code, 3, 67, pypy_code, (), + ('i',)) + f2 = new.function(new_c, locals(), 'f') + + graph = self.codetest(f2) + all_ops = self.all_operations(graph) + assert all_ops == {'newlist': 1, 'getattr': 1, 'simple_call': 1, + 'iter': 1, 'next': 1} + finally: + self.unpatch_opcodes('BUILD_LIST_FROM_ARG') def test_dont_capture_RuntimeError(self): class Foo: _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit