OLD | NEW |
(Empty) | |
| 1 from cpython.ref cimport PyObject |
| 2 |
| 3 cdef extern from "Python.h": |
| 4 |
| 5 ############################################################################ |
| 6 # Lists |
| 7 ############################################################################ |
| 8 object PyList_New(Py_ssize_t len) |
| 9 # Return a new list of length len on success, or NULL on failure. |
| 10 # |
| 11 # Note: If length is greater than zero, the returned list object's |
| 12 # items are set to NULL. Thus you cannot use abstract API |
| 13 # functions such as PySequence_SetItem() or expose the object to |
| 14 # Python code before setting all items to a real object with |
| 15 # PyList_SetItem(). |
| 16 |
| 17 bint PyList_Check(object p) |
| 18 # Return true if p is a list object or an instance of a subtype of |
| 19 # the list type. |
| 20 |
| 21 bint PyList_CheckExact(object p) |
| 22 # Return true if p is a list object, but not an instance of a |
| 23 # subtype of the list type. |
| 24 |
| 25 Py_ssize_t PyList_Size(object list) except -1 |
| 26 # Return the length of the list object in list; this is equivalent |
| 27 # to "len(list)" on a list object. |
| 28 |
| 29 Py_ssize_t PyList_GET_SIZE(object list) |
| 30 # Macro form of PyList_Size() without error checking. |
| 31 |
| 32 PyObject* PyList_GetItem(object list, Py_ssize_t index) except NULL |
| 33 # Return value: Borrowed reference. |
| 34 # Return the object at position pos in the list pointed to by |
| 35 # p. The position must be positive, indexing from the end of the |
| 36 # list is not supported. If pos is out of bounds, return NULL and |
| 37 # set an IndexError exception. |
| 38 |
| 39 PyObject* PyList_GET_ITEM(object list, Py_ssize_t i) |
| 40 # Return value: Borrowed reference. |
| 41 # Macro form of PyList_GetItem() without error checking. |
| 42 |
| 43 int PyList_SetItem(object list, Py_ssize_t index, object item) except -1 |
| 44 # Set the item at index index in list to item. Return 0 on success |
| 45 # or -1 on failure. Note: This function ``steals'' a reference to |
| 46 # item and discards a reference to an item already in the list at |
| 47 # the affected position. |
| 48 |
| 49 void PyList_SET_ITEM(object list, Py_ssize_t i, object o) |
| 50 # Macro form of PyList_SetItem() without error checking. This is |
| 51 # normally only used to fill in new lists where there is no |
| 52 # previous content. Note: This function ``steals'' a reference to |
| 53 # item, and, unlike PyList_SetItem(), does not discard a reference |
| 54 # to any item that it being replaced; any reference in list at |
| 55 # position i will be *leaked*. |
| 56 |
| 57 int PyList_Insert(object list, Py_ssize_t index, object item) except -1 |
| 58 # Insert the item item into list list in front of index |
| 59 # index. Return 0 if successful; return -1 and set an exception if |
| 60 # unsuccessful. Analogous to list.insert(index, item). |
| 61 |
| 62 int PyList_Append(object list, object item) except -1 |
| 63 # Append the object item at the end of list list. Return 0 if |
| 64 # successful; return -1 and set an exception if |
| 65 # unsuccessful. Analogous to list.append(item). |
| 66 |
| 67 object PyList_GetSlice(object list, Py_ssize_t low, Py_ssize_t high) |
| 68 # Return value: New reference. |
| 69 # Return a list of the objects in list containing the objects |
| 70 # between low and high. Return NULL and set an exception if |
| 71 # unsuccessful. Analogous to list[low:high]. |
| 72 |
| 73 int PyList_SetSlice(object list, Py_ssize_t low, Py_ssize_t high, object ite
mlist) except -1 |
| 74 # Set the slice of list between low and high to the contents of |
| 75 # itemlist. Analogous to list[low:high] = itemlist. The itemlist |
| 76 # may be NULL, indicating the assignment of an empty list (slice |
| 77 # deletion). Return 0 on success, -1 on failure. |
| 78 |
| 79 int PyList_Sort(object list) except -1 |
| 80 # Sort the items of list in place. Return 0 on success, -1 on |
| 81 # failure. This is equivalent to "list.sort()". |
| 82 |
| 83 int PyList_Reverse(object list) except -1 |
| 84 # Reverse the items of list in place. Return 0 on success, -1 on |
| 85 # failure. This is the equivalent of "list.reverse()". |
| 86 |
| 87 object PyList_AsTuple(object list) |
| 88 # Return value: New reference. |
| 89 # Return a new tuple object containing the contents of list; |
| 90 # equivalent to "tuple(list)". |
| 91 |
| 92 |
OLD | NEW |