1 from cpython.ref cimport PyObject
3 cdef extern from "Python.h":
5 ############################################################################
7 ############################################################################
8 object PyList_New(Py_ssize_t len)
9 # Return a new list of length len on success, or NULL on failure.
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
17 bint PyList_Check(object p)
18 # Return true if p is a list object or an instance of a subtype of
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.
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.
29 Py_ssize_t PyList_GET_SIZE(object list)
30 # Macro form of PyList_Size() without error checking.
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.
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.
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.
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*.
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).
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).
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].
73 int PyList_SetSlice(object list, Py_ssize_t low, Py_ssize_t high, object itemlist) 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.
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()".
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()".
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)".