[pypy-svn] r73851 - pypy/trunk/pypy/objspace/flow/test

fijal at codespeak.net fijal at codespeak.net
Sun Apr 18 00:10:11 CEST 2010


Author: fijal
Date: Sun Apr 18 00:10:09 2010
New Revision: 73851

Modified:
   pypy/trunk/pypy/objspace/flow/test/test_objspace.py
Log:
A bit more delicate patching so host will recognize LOOKUP and CALL method
bytecodes


Modified: pypy/trunk/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/trunk/pypy/objspace/flow/test/test_objspace.py	(original)
+++ pypy/trunk/pypy/objspace/flow/test/test_objspace.py	Sun Apr 18 00:10:09 2010
@@ -5,8 +5,10 @@
 from pypy.interpreter.argument import Arguments
 from pypy.translator.simplify import simplify_graph
 from pypy.objspace.flow.objspace import FlowObjSpace 
-from pypy.objspace.flow import objspace
+from pypy.objspace.flow import objspace, flowcontext
 from pypy import conftest
+from pypy.tool.stdlib_opcode import bytecode_spec
+from pypy.interpreter.pyframe import PyFrame
 
 import os
 import operator
@@ -837,24 +839,34 @@
         """ Tests code generated by pypy-c compiled with CALL_METHOD
         bytecode
         """
-        py.test.skip("XXX this needs to be fixed, maybe")
-        class X:
-            def m(self):
-                return 3
-
-        def f():
-            x = X()
-            return x.m()
-
-        # this code is generated by pypy-c when compiling above f
-        pypy_code = 't\x00\x00\x83\x00\x00}\x00\x00|\x00\x00\x91\x02\x00\x92\x00\x00Sd\x00\x00S'
-        new_c = self.monkey_patch_code(f.func_code, 3, 3, pypy_code, ('X', 'x', 'm'), ('x',))
-        f2 = new.function(new_c, locals(), 'f')
-        
-        graph = self.codetest(f2)
-        all_ops = self.all_operations(graph)
-        assert all_ops['simple_call'] == 2
-        assert all_ops['getattr'] == 1
+        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]
+        try:
+            class X:
+                def m(self):
+                    return 3
+
+            def f():
+                x = X()
+                return x.m()
+
+            # this code is generated by pypy-c when compiling above f
+            pypy_code = 't\x00\x00\x83\x00\x00}\x00\x00|\x00\x00\x91\x02\x00\x92\x00\x00Sd\x00\x00S'
+            new_c = self.monkey_patch_code(f.func_code, 3, 3, pypy_code, ('X', 'x', 'm'), ('x',))
+            f2 = new.function(new_c, locals(), 'f')
+
+            graph = self.codetest(f2)
+            all_ops = self.all_operations(graph)
+            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]
 
     def test_generator(self):
         def f():



More information about the Pypy-commit mailing list