[pypy-svn] r30361 - in pypy/dist/pypy/objspace/cpy: . test

arigo at codespeak.net arigo at codespeak.net
Sat Jul 22 17:20:12 CEST 2006


Author: arigo
Date: Sat Jul 22 17:20:10 2006
New Revision: 30361

Modified:
   pypy/dist/pypy/objspace/cpy/capi.py
   pypy/dist/pypy/objspace/cpy/objspace.py
   pypy/dist/pypy/objspace/cpy/test/test_objspace.py
Log:
Reimplement lookup() for the cpyobjspace.  Also makes space.callable() work.


Modified: pypy/dist/pypy/objspace/cpy/capi.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/capi.py	(original)
+++ pypy/dist/pypy/objspace/cpy/capi.py	Sat Jul 22 17:20:10 2006
@@ -224,6 +224,10 @@
 PyType_IsSubtype.argtypes = [W_Object, W_Object]
 PyType_IsSubtype.restype = c_int
 
+_PyType_Lookup = cpyapi._PyType_Lookup
+_PyType_Lookup.argtypes = [W_Object, W_Object]
+_PyType_Lookup.restype = W_Object
+
 
 ###########################################################
 # ____________________ Numeric Objects ____________________

Modified: pypy/dist/pypy/objspace/cpy/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/objspace.py	(original)
+++ pypy/dist/pypy/objspace/cpy/objspace.py	Sat Jul 22 17:20:10 2006
@@ -1,4 +1,6 @@
+import types
 from pypy.objspace.cpy.capi import *
+from pypy.objspace.cpy.capi import _PyType_Lookup
 from pypy.objspace.cpy.refcount import Py_Incref
 from pypy.objspace.cpy.appsupport import W_AppLevel
 from pypy.interpreter import baseobjspace
@@ -25,6 +27,7 @@
     w_str            = W_Object(str)
     w_unicode        = W_Object(unicode)
     w_type           = W_Object(type)
+    w_instance       = W_Object(types.InstanceType)
 
     w_hex            = W_Object(hex) # no C API function to do that :-(
     w_oct            = W_Object(oct)
@@ -102,6 +105,16 @@
         return cpython2rpython(self, RequiredClass, w_obj)
     interp_w._annspecialcase_ = 'specialize:arg(1)'
 
+    def lookup(self, w_obj, name):
+        w_type = self.type(w_obj)
+        w_name = self.wrap(name)
+        w_res = _PyType_Lookup(w_type, w_name)
+        if w_res:
+            Py_Incref(w_res)
+            return w_res
+        else:
+            return None
+
     # __________ operations with a direct CPython equivalent __________
 
     getattr = staticmethod(PyObject_GetAttr)

Modified: pypy/dist/pypy/objspace/cpy/test/test_objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/test/test_objspace.py	(original)
+++ pypy/dist/pypy/objspace/cpy/test/test_objspace.py	Sat Jul 22 17:20:10 2006
@@ -114,3 +114,22 @@
         assert hasattr(space, 'w_' + name)
     for name in ObjSpace.IrregularOpTable:
         assert hasattr(space, name)
+
+def test_lookup():
+    space = CPyObjSpace()
+    class X(object):
+        def f():
+            return 5
+    def g():
+        return 7
+    x = X()
+    x.f = g
+    w = space.W_Object(x)
+    w_f = space.lookup(w, "f")
+    w_5 = space.call_function(w_f)
+    assert space.int_w(w_5) == 5
+
+def test_callable():
+    space = CPyObjSpace()
+    assert space.is_true(space.callable(space.w_int))
+    assert not space.is_true(space.callable(space.w_Ellipsis))



More information about the Pypy-commit mailing list