list.pxd 4.0 KB

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