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

agaynor at codespeak.net agaynor at codespeak.net
Sun Apr 4 17:34:53 CEST 2010


Author: agaynor
Date: Sun Apr  4 17:34:51 2010
New Revision: 73358

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/sequence.py
   pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sequence.py
Log:
Implemented PySequence_GetSlice

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/sequence.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/sequence.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/sequence.py	Sun Apr  4 17:34:51 2010
@@ -44,3 +44,11 @@
     assert isinstance(w_obj, tupleobject.W_TupleObject)
     return len(w_obj.wrappeditems)
 
+ at cpython_api([PyObject, Py_ssize_t, Py_ssize_t], PyObject)
+def PySequence_GetSlice(space, w_obj, w_start, w_end):
+    """Return the slice of sequence object o between i1 and i2, or NULL on
+    failure. This is the equivalent of the Python expression o[i1:i2].
+    
+    This function used an int type for i1 and i2. This might
+    require changes in your code for properly supporting 64-bit systems."""
+    return space.getslice(w_obj, w_start, w_end)

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  4 17:34:51 2010
@@ -4820,15 +4820,6 @@
     changes in your code for properly supporting 64-bit systems."""
     raise NotImplementedError
 
- at cpython_api([PyObject, Py_ssize_t, Py_ssize_t], PyObject)
-def PySequence_GetSlice(space, o, i1, i2):
-    """Return the slice of sequence object o between i1 and i2, or NULL on
-    failure. This is the equivalent of the Python expression o[i1:i2].
-    
-    This function used an int type for i1 and i2. This might
-    require changes in your code for properly supporting 64-bit systems."""
-    raise NotImplementedError
-
 @cpython_api([PyObject, Py_ssize_t, PyObject], rffi.INT_real)
 def PySequence_SetItem(space, o, i, v):
     """Assign object v to the ith element of o.  Returns -1 on failure.  This

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sequence.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sequence.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sequence.py	Sun Apr  4 17:34:51 2010
@@ -29,3 +29,8 @@
         assert exc.value.match(space, space.w_TypeError)
         assert space.str_w(exc.value.get_w_value(space)) == "message"
         rffi.free_charp(message)
+    
+    def test_get_slice(self, space, api):
+        w_t = space.wrap((1, 2, 3, 4, 5))
+        assert space.unwrap(api.PySequence_GetSlice(w_t, space.wrap(2), space.wrap(4))) == (3, 4)
+        assert space.unwrap(api.PySequence_GetSlice(w_t, space.wrap(1), space.wrap(-1))) == (2, 3, 4)



More information about the Pypy-commit mailing list