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

jandem at codespeak.net jandem at codespeak.net
Tue Mar 23 21:18:06 CET 2010


Author: jandem
Date: Tue Mar 23 21:17:56 2010
New Revision: 72659

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/include/tupleobject.h
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_cpyext.py
   pypy/branch/cpython-extension/pypy/module/cpyext/tupleobject.py
Log:
Add PyTuple_GetItem and a failing test


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/tupleobject.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/tupleobject.h	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/tupleobject.h	Tue Mar 23 21:17:56 2010
@@ -9,6 +9,7 @@
 
 PyObject * PyTuple_New(Py_ssize_t size);
 PyObject * PyTuple_Pack(Py_ssize_t, ...);
+PyObject * PyTuple_GetItem(PyObject *, Py_ssize_t);
 int PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);
 
 #ifdef __cplusplus

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_cpyext.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_cpyext.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_cpyext.py	Tue Mar 23 21:17:56 2010
@@ -224,6 +224,25 @@
         skip("Hmm, how to check for the exception?")
         raises(api.InvalidPointerException, module.return_invalid_pointer)
 
+    def test_argument(self):
+        import sys
+        init = """
+        if (Py_IsInitialized())
+            Py_InitModule("foo", methods);
+        """
+        body = """
+        PyObject* foo_test(PyObject* self, PyObject *args)
+        {
+            return PyTuple_GetItem(args, 0);
+        }
+        static PyMethodDef methods[] = {
+            { "test", foo_test, METH_VARARGS },
+            { NULL }
+        };
+        """
+        module = self.import_module(name='foo', init=init, body=body)
+        assert module.test(True, True) == True
+
     def test_exception(self):
         import sys
         init = """

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/tupleobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/tupleobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/tupleobject.py	Tue Mar 23 21:17:56 2010
@@ -14,3 +14,9 @@
     w_t.wrappeditems[pos] = w_obj
     Py_DECREF(space, w_obj) # SetItem steals a reference!
     return 0
+
+ at cpython_api([PyObject, Py_ssize_t], PyObject)
+def PyTuple_GetItem(space, w_t, pos):
+    assert isinstance(w_t, W_TupleObject)
+    w_obj = w_t.wrappeditems[pos]
+    return w_obj



More information about the Pypy-commit mailing list