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

afa at codespeak.net afa at codespeak.net
Sat May 22 00:17:07 CEST 2010


Author: afa
Date: Sat May 22 00:17:05 2010
New Revision: 74661

Modified:
   pypy/trunk/pypy/module/cpyext/sequence.py
   pypy/trunk/pypy/module/cpyext/stubs.py
   pypy/trunk/pypy/module/cpyext/test/test_sequence.py
Log:
PySequence_SetSlice, PySequence_DelSlice


Modified: pypy/trunk/pypy/module/cpyext/sequence.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/sequence.py	(original)
+++ pypy/trunk/pypy/module/cpyext/sequence.py	Sat May 22 00:17:05 2010
@@ -67,12 +67,23 @@
 @cpython_api([PyObject, Py_ssize_t, Py_ssize_t], PyObject)
 def PySequence_GetSlice(space, w_obj, start, 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."""
+    failure. This is the equivalent of the Python expression o[i1:i2]."""
     return space.getslice(w_obj, space.wrap(start), space.wrap(end))
 
+ at cpython_api([PyObject, Py_ssize_t, Py_ssize_t, PyObject], rffi.INT_real, error=-1)
+def PySequence_SetSlice(space, w_obj, start, end, w_value):
+    """Assign the sequence object v to the slice in sequence object o from i1 to
+    i2.  This is the equivalent of the Python statement o[i1:i2] = v."""
+    space.setslice(w_obj, space.wrap(start), space.wrap(end), w_value)
+    return 0
+
+ at cpython_api([PyObject, Py_ssize_t, Py_ssize_t], rffi.INT_real, error=-1)
+def PySequence_DelSlice(space, w_obj, start, end):
+    """Delete the slice in sequence object o from i1 to i2.  Returns -1 on
+    failure.  This is the equivalent of the Python statement del o[i1:i2]."""
+    space.delslice(w_obj, space.wrap(start), space.wrap(end))
+    return 0
+
 @cpython_api([PyObject, Py_ssize_t], PyObject)
 def PySequence_GetItem(space, w_obj, i):
     """Return the ith element of o, or NULL on failure. This is the equivalent of

Modified: pypy/trunk/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/stubs.py	(original)
+++ pypy/trunk/pypy/module/cpyext/stubs.py	Sat May 22 00:17:05 2010
@@ -2459,24 +2459,6 @@
     changes in your code for properly supporting 64-bit systems."""
     raise NotImplementedError
 
- at cpython_api([PyObject, Py_ssize_t, Py_ssize_t, PyObject], rffi.INT_real, error=-1)
-def PySequence_SetSlice(space, o, i1, i2, v):
-    """Assign the sequence object v to the slice in sequence object o from i1 to
-    i2.  This is the equivalent of the Python statement o[i1:i2] = v.
-    
-    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
-
- at cpython_api([PyObject, Py_ssize_t, Py_ssize_t], rffi.INT_real, error=-1)
-def PySequence_DelSlice(space, o, i1, i2):
-    """Delete the slice in sequence object o from i1 to i2.  Returns -1 on
-    failure.  This is the equivalent of the Python statement del 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, PyObject], Py_ssize_t, error=-1)
 def PySequence_Count(space, o, value):
     """Return the number of occurrences of value in o, that is, return the number

Modified: pypy/trunk/pypy/module/cpyext/test/test_sequence.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_sequence.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_sequence.py	Sat May 22 00:17:05 2010
@@ -41,9 +41,14 @@
         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, 2, 4)) == (3, 4)
-        assert space.unwrap(api.PySequence_GetSlice(w_t, 1, -1)) == (2, 3, 4)
+        w_t = space.wrap([1, 2, 3, 4, 5])
+        assert space.unwrap(api.PySequence_GetSlice(w_t, 2, 4)) == [3, 4]
+        assert space.unwrap(api.PySequence_GetSlice(w_t, 1, -1)) == [2, 3, 4]
+
+        assert api.PySequence_DelSlice(w_t, 1, 4) == 0
+        assert space.eq_w(w_t, space.wrap([1, 5]))
+        assert api.PySequence_SetSlice(w_t, 1, 1, space.wrap((3,))) == 0
+        assert space.eq_w(w_t, space.wrap([1, 3, 5]))
 
     def test_iter(self, space, api):
         w_t = space.wrap((1, 2))



More information about the Pypy-commit mailing list