[pypy-svn] r74172 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test

afa at codespeak.net afa at codespeak.net
Wed Apr 28 14:56:54 CEST 2010


Author: afa
Date: Wed Apr 28 14:56:52 2010
New Revision: 74172

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/object.py
   pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py
Log:
PyObject_GetAttr, PyObject_DelAttr


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/object.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/object.py	Wed Apr 28 14:56:52 2010
@@ -71,6 +71,13 @@
 def PyObject_Not(space, w_obj):
     return not space.is_true(w_obj)
 
+ at cpython_api([PyObject, PyObject], PyObject)
+def PyObject_GetAttr(space, w_obj, w_name):
+    """Retrieve an attribute named attr_name from object o. Returns the attribute
+    value on success, or NULL on failure.  This is the equivalent of the Python
+    expression o.attr_name."""
+    return space.getattr(w_obj, w_name)
+
 @cpython_api([PyObject, CONST_STRING], PyObject)
 def PyObject_GetAttrString(space, w_obj, name_ptr):
     """Retrieve an attribute named attr_name from object o. Returns the attribute
@@ -107,6 +114,13 @@
     operation.setattr(space, w_obj, w_name, w_value)
     return 0
 
+ at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
+def PyObject_DelAttr(space, w_obj, w_name):
+    """Delete attribute named attr_name, for object o. Returns -1 on failure.
+    This is the equivalent of the Python statement del o.attr_name."""
+    space.delattr(w_obj, w_name)
+    return 0
+
 @cpython_api([PyObject], lltype.Void)
 def PyObject_ClearWeakRefs(space, w_object):
     w_object.clear_all_weakrefs()

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py	Wed Apr 28 14:56:52 2010
@@ -3023,19 +3023,6 @@
     require changes in your code for properly supporting 64-bit systems."""
     raise NotImplementedError
 
- at cpython_api([PyObject, PyObject], PyObject)
-def PyObject_GetAttr(space, o, attr_name):
-    """Retrieve an attribute named attr_name from object o. Returns the attribute
-    value on success, or NULL on failure.  This is the equivalent of the Python
-    expression o.attr_name."""
-    raise NotImplementedError
-
- at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
-def PyObject_DelAttr(space, o, attr_name):
-    """Delete attribute named attr_name, for object o. Returns -1 on failure.
-    This is the equivalent of the Python statement del o.attr_name."""
-    raise NotImplementedError
-
 @cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
 def PyObject_DelAttrString(space, o, attr_name):
     """Delete attribute named attr_name, for object o. Returns -1 on failure.

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py	Wed Apr 28 14:56:52 2010
@@ -54,7 +54,7 @@
         rffi.free_charp(buf)
         assert x.test == 20
 
-    def test_getattr_string(self, space, api):
+    def test_getattr(self, space, api):
         charp1 = rffi.str2charp("__len__")
         charp2 = rffi.str2charp("not_real")
         assert api.PyObject_GetAttrString(space.wrap(""), charp1)
@@ -64,6 +64,10 @@
         rffi.free_charp(charp1)
         rffi.free_charp(charp2)
 
+        assert api.PyObject_GetAttr(space.wrap(""), space.wrap("__len__"))
+        assert api.PyObject_DelAttr(space.wrap(""), space.wrap("__len__")) == -1
+        api.PyErr_Clear()
+
     def test_getitem(self, space, api):
         w_t = space.wrap((1, 2, 3, 4, 5))
         assert space.unwrap(api.PyObject_GetItem(w_t, space.wrap(3))) == 4



More information about the Pypy-commit mailing list