[pypy-svn] r74772 - in pypy/trunk/pypy/module/cpyext: . test

afa at codespeak.net afa at codespeak.net
Wed May 26 13:55:02 CEST 2010


Author: afa
Date: Wed May 26 13:55:00 2010
New Revision: 74772

Modified:
   pypy/trunk/pypy/module/cpyext/test/test_typeobject.py
   pypy/trunk/pypy/module/cpyext/typeobject.py
Log:
Add _PyType_Lookup, not documented but used by Boost.Python...


Modified: pypy/trunk/pypy/module/cpyext/test/test_typeobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_typeobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_typeobject.py	Wed May 26 13:55:00 2010
@@ -173,3 +173,12 @@
             """)
         ref = make_ref(space, w_class)
         api.Py_DecRef(ref)
+
+    def test_lookup(self, space, api):
+        w_type = space.w_str
+        w_obj = api._PyType_Lookup(w_type, space.wrap("upper"))
+        assert space.is_w(w_obj, space.w_str.getdictvalue(space, "upper"))
+
+        w_obj = api._PyType_Lookup(w_type, space.wrap("__invalid"))
+        assert w_obj is None
+        assert api.PyErr_Occurred() is None

Modified: pypy/trunk/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/typeobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/typeobject.py	Wed May 26 13:55:00 2010
@@ -17,7 +17,7 @@
     PyBufferProcs, build_type_checkers)
 from pypy.module.cpyext.pyobject import (
     PyObject, make_ref, create_ref, from_ref, get_typedescr, make_typedescr,
-    track_reference, RefcountState)
+    track_reference, RefcountState, borrow_from)
 from pypy.interpreter.module import Module
 from pypy.interpreter.function import FunctionWithFixedCode, StaticMethod
 from pypy.module.cpyext import structmemberdefs
@@ -675,4 +675,14 @@
     return generic_cpy_call(
         space, type.c_tp_alloc, type, 0)
 
+ at cpython_api([PyTypeObjectPtr, PyObject], PyObject, error=CANNOT_FAIL)
+def _PyType_Lookup(space, type, w_name):
+    """Internal API to look for a name through the MRO.
+    This returns a borrowed reference, and doesn't set an exception!"""
+    py_type = rffi.cast(PyObject, type)
+    w_type = from_ref(space, py_type)
+    assert isinstance(w_type, W_TypeObject)
+    name = space.str_w(w_name)
+    w_obj = w_type.lookup(name)
+    return borrow_from(w_type, w_obj)
 



More information about the Pypy-commit mailing list