[pypy-svn] r73895 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
agaynor at codespeak.net
agaynor at codespeak.net
Tue Apr 20 09:03:12 CEST 2010
Author: agaynor
Date: Tue Apr 20 09:03:10 2010
New Revision: 73895
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:
Implement PyList_Sort
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 Tue Apr 20 09:03:10 2010
@@ -83,3 +83,10 @@
raise OperationError(space.w_TypeError,
space.wrap("expected list object"))
return PyList_GET_SIZE(space, ref)
+
+ at 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
+ failure. This is equivalent to list.sort()."""
+ space.call_method(w_list, "sort")
+ return 0
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 Tue Apr 20 09:03:10 2010
@@ -3385,12 +3385,6 @@
raise NotImplementedError
@cpython_api([PyObject], rffi.INT_real)
-def PyList_Sort(space, list):
- """Sort the items of list in place. Return 0 on success, -1 on
- failure. This is equivalent to list.sort()."""
- raise NotImplementedError
-
- at cpython_api([PyObject], rffi.INT_real)
def PyList_Reverse(space, list):
"""Reverse the items of list in place. Return 0 on success, -1 on
failure. This is the equivalent of list.reverse()."""
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 Tue Apr 20 09:03:10 2010
@@ -32,6 +32,11 @@
assert api.PyList_Size(space.w_None) == -1
assert api.PyErr_Occurred() is space.w_TypeError
api.PyErr_Clear()
+
+ def test_sort(self, space, api):
+ l = space.newlist([space.wrap(1), space.wrap(0), space.wrap(7000)])
+ assert api.PyList_Sort(l) == 0
+ assert space.eq_w(l, space.newlist([space.wrap(0), space.wrap(1), space.wrap(7000)]))
class AppTestListObject(AppTestCpythonExtensionBase):
def test_listobject(self):
More information about the Pypy-commit
mailing list