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

dan at codespeak.net dan at codespeak.net
Sun Jun 6 00:50:15 CEST 2010


Author: dan
Date: Sun Jun  6 00:50:14 2010
New Revision: 75139

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:
Added PySequence_Repeat() along with the relevant tests, and fixed test_sequence.

Modified: pypy/trunk/pypy/module/cpyext/sequence.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/sequence.py	(original)
+++ pypy/trunk/pypy/module/cpyext/sequence.py	Sun Jun  6 00:50:14 2010
@@ -6,6 +6,14 @@
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.objspace.std import listobject, tupleobject
 
+ at cpython_api([PyObject, Py_ssize_t], PyObject)
+def PySequence_Repeat(space, w_obj, count):
+    """Return the result of repeating sequence object o count times, or NULL on
+    failure.  This is the equivalent of the Python expression o * count.
+    
+    This function used an int type for count. This might require
+    changes in your code for properly supporting 64-bit systems."""
+    return space.mul(w_obj, space.wrap(count))
 
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def PySequence_Check(space, w_obj):

Modified: pypy/trunk/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/stubs.py	(original)
+++ pypy/trunk/pypy/module/cpyext/stubs.py	Sun Jun  6 00:50:14 2010
@@ -2363,9 +2363,7 @@
 
 @cpython_api([PyObject], PyObject)
 def PyObject_Dir(space, o):
-    """This is equivalent to the Python expression dir(o), returning a (possibly
-    empty) list of strings appropriate for the object argument, or NULL if there
-    was an error.  If the argument is NULL, this is like the Python dir(),
+    """This is equivalent to the Python expression dir(o), returning a (possibly empty) list of strings appropriate for the object argument, or NULL if there was an error.  If the argument is NULL, this is like the Python dir(),
     returning the names of the current locals; in this case, if no execution frame
     is active then NULL is returned but PyErr_Occurred() will return false."""
     raise NotImplementedError
@@ -2403,15 +2401,6 @@
     func."""
     raise NotImplementedError
 
- at cpython_api([PyObject, Py_ssize_t], PyObject)
-def PySequence_Repeat(space, o, count):
-    """Return the result of repeating sequence object o count times, or NULL on
-    failure.  This is the equivalent of the Python expression o * count.
-    
-    This function used an int type for count. This might require
-    changes in your code for properly supporting 64-bit systems."""
-    raise NotImplementedError
-
 @cpython_api([PyObject, PyObject], PyObject)
 def PySequence_InPlaceConcat(space, o1, o2):
     """Return the concatenation of o1 and o2 on success, and NULL on failure.

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	Sun Jun  6 00:50:14 2010
@@ -8,7 +8,7 @@
     def test_sequence(self, space, api):
         w_t = space.wrap((1, 2, 3, 4))
         assert api.PySequence_Fast(w_t, "message") is w_t
-        w_l = space.wrap((1, 2, 3, 4))
+        w_l = space.wrap([1, 2, 3, 4])
         assert api.PySequence_Fast(w_l, "message") is w_l
 
         assert space.int_w(api.PySequence_Fast_GET_ITEM(w_l, 1)) == 2
@@ -23,6 +23,15 @@
         assert space.type(w_seq) is space.w_tuple
         assert sorted(space.unwrap(w_seq)) == [1, 2, 3, 4]
 
+    def test_repeat(self, space, api):
+        def test(seq, count):
+            w_seq = space.wrap(seq)
+            w_repeated = api.PySequence_Repeat(w_seq, count)
+            assert space.eq_w(w_repeated, space.wrap(seq * count))
+
+        test((1, 2, 3, 4), 3)
+        test([1, 2, 3, 4], 3)
+
     def test_concat(self, space, api):
         w_t1 = space.wrap(range(4))
         w_t2 = space.wrap(range(4, 8))



More information about the Pypy-commit mailing list