[pypy-svn] r54316 - in pypy/branch/oo-jit/pypy/rpython/ootypesystem: . test

antocuni at codespeak.net antocuni at codespeak.net
Fri May 2 12:37:34 CEST 2008


Author: antocuni
Date: Fri May  2 12:37:32 2008
New Revision: 54316

Modified:
   pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py
   pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_oortype.py
Log:
a hack; since pbc unbound methods are not supported in general,
provide a way to build a wrapper that calls it, given the name




Modified: pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py	Fri May  2 12:37:32 2008
@@ -1882,6 +1882,20 @@
     ref.ll_set(obj)
     return ref
 
+def build_unbound_method_wrapper(meth):
+    METH = typeOf(meth)
+    methname = meth._name
+    funcname = '%s_wrapper' % methname
+    nb_args = len(METH.ARGS)
+    arglist = ', '.join('a%d' % i for i in range(nb_args))
+    ns = {'methname': methname}
+    code = py.code.Source("""
+    def %s(self, %s):
+        m = getattr(self, methname)
+        return m(%s)
+    """ % (funcname, arglist, arglist))
+    exec code.compile() in ns
+    return ns[funcname]
 
 Object = Object()
 NULL = _object(None)

Modified: pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_oortype.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_oortype.py	(original)
+++ pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_oortype.py	Fri May  2 12:37:32 2008
@@ -337,3 +337,16 @@
         return oodowncast(A, c)
 
     py.test.raises(AnnotatorError, interpret, fn, [], type_system='ootype')
+
+def test_method_wrapper():
+    L = List(Signed)
+    _, meth = L._lookup('ll_getitem_fast')
+    wrapper = build_unbound_method_wrapper(meth)
+
+    def fn():
+        lst = L.ll_newlist(1)
+        lst.ll_setitem_fast(0, 42)
+        return wrapper(lst, 0)
+    
+    res = interpret(fn, [], type_system='ootype')
+    assert res == 42



More information about the Pypy-commit mailing list