[pypy-svn] r49709 - in pypy/branch/pypy-gc-traceopt/annotation: . test

arigo at codespeak.net arigo at codespeak.net
Thu Dec 13 13:40:54 CET 2007


Author: arigo
Date: Thu Dec 13 13:40:54 2007
New Revision: 49709

Modified:
   pypy/branch/pypy-gc-traceopt/annotation/specialize.py
   pypy/branch/pypy-gc-traceopt/annotation/test/test_annrpython.py
Log:
Merge of r49697 from the trunk.


Modified: pypy/branch/pypy-gc-traceopt/annotation/specialize.py
==============================================================================
--- pypy/branch/pypy-gc-traceopt/annotation/specialize.py	(original)
+++ pypy/branch/pypy-gc-traceopt/annotation/specialize.py	Thu Dec 13 13:40:54 2007
@@ -421,7 +421,19 @@
     return constgraphbuilder
 
 def specialize_argvalue(funcdesc, args_s, *argindices):
-    key = tuple([args_s[i].const for i in argindices])
+    from pypy.annotation.model import SomePBC
+    key = []
+    for i in argindices:
+        s = args_s[i]
+        if s.is_constant():
+            key.append(s.const)
+        elif isinstance(s, SomePBC) and len(s.descriptions) == 1:
+            # for test_specialize_arg_bound_method
+            key.append(s.descriptions.keys()[0])
+        else:
+            raise Exception("specialize:arg(%d): argument not constant: %r"
+                            % (i, s))
+    key = tuple(key)
     return funcdesc.cachedgraph(key)
 
 def specialize_argtype(funcdesc, args_s, *argindices):

Modified: pypy/branch/pypy-gc-traceopt/annotation/test/test_annrpython.py
==============================================================================
--- pypy/branch/pypy-gc-traceopt/annotation/test/test_annrpython.py	(original)
+++ pypy/branch/pypy-gc-traceopt/annotation/test/test_annrpython.py	Thu Dec 13 13:40:54 2007
@@ -1099,6 +1099,32 @@
         assert graph1 in a.translator.graphs
         assert graph2 in a.translator.graphs
 
+    def test_specialize_arg_bound_method(self):
+        class GC(object):
+            def trace(self, callback, arg):
+                return callback(arg)
+            trace._annspecialcase_ = "specialize:arg(1)"
+
+            def callback1(self, arg):
+                self.x = arg
+                return "hello"
+
+            def callback2(self, arg):
+                self.y = arg
+                return 6
+
+        def f():
+            gc = GC()
+            s1 = gc.trace(gc.callback1, None)
+            n2 = gc.trace(gc.callback2, 7)
+            return (s1, n2, gc.x, gc.y)
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [])
+        assert s.items[0].const == "hello"
+        assert s.items[1].const == 6
+        assert s.items[2].const == None
+        assert s.items[3].const == 7
+
     def test_assert_list_doesnt_lose_info(self):
         class T(object):
             pass



More information about the Pypy-commit mailing list