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

xoraxax at codespeak.net xoraxax at codespeak.net
Sun Apr 4 19:17:26 CEST 2010


Author: xoraxax
Date: Sun Apr  4 19:17:25 2010
New Revision: 73363

Added:
   pypy/branch/cpython-extension/pypy/module/cpyext/include/listobject.h   (contents, props changed)
Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/listobject.py
Log:
Add PyList_GET_ITEM define and PyList_GetItem impl.

Added: pypy/branch/cpython-extension/pypy/module/cpyext/include/listobject.h
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/listobject.h	Sun Apr  4 19:17:25 2010
@@ -0,0 +1 @@
+#define PyList_GET_ITEM PyList_GetItem

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	Sun Apr  4 19:17:25 2010
@@ -39,6 +39,22 @@
     wrappeditems[index] = w_item
     return 0
 
+ at cpython_api([PyObject, Py_ssize_t], PyObject, borrowed=True)
+def PyList_GetItem(space, w_list, index):
+    """Return the object at position pos in the list pointed to by p.  The
+    position must be positive, indexing from the end of the list is not
+    supported.  If pos is out of bounds, return NULL and set an
+    IndexError exception."""
+    register_container(space, w_list)
+    if not isinstance(w_list, W_ListObject):
+        PyErr_BadInternalCall(space)
+    wrappeditems = w_list.wrappeditems
+    if index < 0 or index >= len(wrappeditems):
+        raise OperationError(space.w_IndexError, space.wrap(
+            "list index out of range"))
+    return wrappeditems[index]
+
+
 @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
 def PyList_Append(space, w_list, w_item):
     if not isinstance(w_list, W_ListObject):



More information about the Pypy-commit mailing list