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

agaynor at codespeak.net agaynor at codespeak.net
Sat Mar 27 22:35:56 CET 2010


Author: agaynor
Date: Sat Mar 27 22:35:54 2010
New Revision: 72986

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

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	Sat Mar 27 22:35:54 2010
@@ -36,3 +36,10 @@
             "list assignment index out of range"))
     wrappeditems[index] = w_item
     return 0
+
+ at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
+def PyList_Append(space, w_list, w_item):
+    if not isinstance(w_list, W_ListObject):
+        PyErr_BadInternalCall(space)
+    w_list.append(w_item)
+    return 0

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	Sat Mar 27 22:35:54 2010
@@ -26,7 +26,14 @@
              Py_INCREF(Py_None);
              return Py_None;
              """
-             )
+             ),
+             ("appendlist", "METH_VARARGS",
+             """
+             PyObject *l = PyTuple_GetItem(args, 0);
+             PyList_Append(l, PyTuple_GetItem(args, 1));
+             Py_RETURN_NONE;
+             """
+             ),
             ])
         l = module.newlist()
         assert l == [3, -5, 1000]
@@ -42,3 +49,9 @@
         assert len(l) == 1
         
         raises(SystemError, module.setlistitem, (1, 2, 3), 0)
+    
+        l = []
+        module.appendlist(l, 14)
+        assert len(l) == 1
+        assert l[0] == 14
+



More information about the Pypy-commit mailing list