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

afa at codespeak.net afa at codespeak.net
Wed Apr 28 17:20:00 CEST 2010


Author: afa
Date: Wed Apr 28 17:19:59 2010
New Revision: 74182

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/listobject.py
   pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_listobject.py
Log:
PyList_AsTuple


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/listobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/listobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/listobject.py	Wed Apr 28 17:19:59 2010
@@ -92,6 +92,12 @@
                              space.wrap("expected list object"))
     return PyList_GET_SIZE(space, ref)
 
+ at cpython_api([PyObject], PyObject)
+def PyList_AsTuple(space, w_list):
+    """Return a new tuple object containing the contents of list; equivalent to
+    tuple(list)."""
+    return space.call_function(space.w_tuple, w_list)
+
 @cpython_api([PyObject], rffi.INT_real, error=-1)
 def PyList_Sort(space, w_list):
     """Sort the items of list in place.  Return 0 on success, -1 on

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 17:19:59 2010
@@ -2640,16 +2640,6 @@
     require changes in your code for properly supporting 64-bit systems."""
     raise NotImplementedError
 
- at cpython_api([PyObject], PyObject)
-def PyList_AsTuple(space, list):
-    """
-    
-    
-    
-    Return a new tuple object containing the contents of list; equivalent to
-    tuple(list)."""
-    raise NotImplementedError
-
 @cpython_api([Py_ssize_t], PyObject)
 def PyLong_FromSsize_t(space, v):
     """Return a new PyLongObject object from a C Py_ssize_t, or

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_listobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_listobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_listobject.py	Wed Apr 28 17:19:59 2010
@@ -53,6 +53,11 @@
         assert api.PyList_Reverse(l) == 0
         assert space.eq_w(l, space.newlist([space.wrap(1), space.wrap(2), space.wrap(3)]))
 
+    def test_list_tuple(self, space, api):
+        w_l = space.newlist([space.wrap(3), space.wrap(2), space.wrap(1)])
+        w_t = api.PyList_AsTuple(w_l)
+        assert space.unwrap(w_t) == (3, 2, 1)
+
 class AppTestListObject(AppTestCpythonExtensionBase):
     def test_listobject(self):
         import sys



More information about the Pypy-commit mailing list