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

agaynor at codespeak.net agaynor at codespeak.net
Sun Apr 11 21:51:07 CEST 2010


Author: agaynor
Date: Sun Apr 11 21:51:04 2010
New Revision: 73651

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:
Implemented PyObject_Length

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	Sun Apr 11 21:51:04 2010
@@ -96,6 +96,17 @@
 def PyObject_Size(space, w_obj):
     return space.int_w(space.len(w_obj))
 
+ at cpython_api([PyObject], Py_ssize_t, error=-1)
+def PyObject_Length(space, w_obj):
+    """
+    Return the length of object o.  If the object o provides either the sequence
+    and mapping protocols, the sequence length is returned.  On error, -1 is
+    returned.  This is the equivalent to the Python expression len(o).
+    
+    These functions returned an int type. This might require
+    changes in your code for properly supporting 64-bit systems."""
+    return PyObject_Size(space, w_obj)
+
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def PyCallable_Check(space, w_obj):
     """Determine if the object o is callable.  Return 1 if the object is callable

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	Sun Apr 11 21:51:04 2010
@@ -4568,20 +4568,6 @@
     """
     raise NotImplementedError
 
- at cpython_api([PyObject], Py_ssize_t)
-def PyObject_Length(space, o):
-    """
-    
-    
-    
-    Return the length of object o.  If the object o provides either the sequence
-    and mapping protocols, the sequence length is returned.  On error, -1 is
-    returned.  This is the equivalent to the Python expression len(o).
-    
-    These functions returned an int type. This might require
-    changes in your code for properly supporting 64-bit systems."""
-    raise NotImplementedError
-
 @cpython_api([PyObject, PyObject, PyObject], rffi.INT_real)
 def PyObject_SetItem(space, o, key, v):
     """Map the object key to the value v.  Returns -1 on failure.  This is the

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	Sun Apr 11 21:51:04 2010
@@ -64,6 +64,7 @@
 
     def test_size(self, space, api):
         assert api.PyObject_Size(space.newlist([space.w_None])) == 1
+        assert api.PyObject_Length(space.newlist([space.w_None])) == 1
         
     def test_repr(self, space, api):
         w_list = space.newlist([space.w_None, space.wrap(42)])



More information about the Pypy-commit mailing list