tuple.pxd 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from .object cimport PyObject
  2. cdef extern from "Python.h":
  3. ############################################################################
  4. # Tuples
  5. ############################################################################
  6. bint PyTuple_Check(object p)
  7. # Return true if p is a tuple object or an instance of a subtype
  8. # of the tuple type.
  9. bint PyTuple_CheckExact(object p)
  10. # Return true if p is a tuple object, but not an instance of a subtype of the tuple type.
  11. tuple PyTuple_New(Py_ssize_t len)
  12. # Return value: New reference.
  13. # Return a new tuple object of size len, or NULL on failure.
  14. tuple PyTuple_Pack(Py_ssize_t n, ...)
  15. # Return value: New reference.
  16. # Return a new tuple object of size n, or NULL on failure. The
  17. # tuple values are initialized to the subsequent n C arguments
  18. # pointing to Python objects. "PyTuple_Pack(2, a, b)" is
  19. # equivalent to "Py_BuildValue("(OO)", a, b)".
  20. Py_ssize_t PyTuple_Size(object p) except -1
  21. # Take a pointer to a tuple object, and return the size of that tuple.
  22. Py_ssize_t PyTuple_GET_SIZE(object p)
  23. # Return the size of the tuple p, which must be non-NULL and point
  24. # to a tuple; no error checking is performed.
  25. PyObject* PyTuple_GetItem(object p, Py_ssize_t pos) except NULL
  26. # Return value: Borrowed reference.
  27. # Return the object at position pos in the tuple pointed to by
  28. # p. If pos is out of bounds, return NULL and sets an IndexError
  29. # exception.
  30. PyObject* PyTuple_GET_ITEM(object p, Py_ssize_t pos)
  31. # Return value: Borrowed reference.
  32. # Like PyTuple_GetItem(), but does no checking of its arguments.
  33. tuple PyTuple_GetSlice(object p, Py_ssize_t low, Py_ssize_t high)
  34. # Return value: New reference.
  35. # Take a slice of the tuple pointed to by p from low to high and return it as a new tuple.
  36. int PyTuple_SetItem(object p, Py_ssize_t pos, object o) except -1
  37. # Insert a reference to object o at position pos of the tuple
  38. # pointed to by p. Return 0 on success. Note: This function
  39. # ``steals'' a reference to o.
  40. void PyTuple_SET_ITEM(object p, Py_ssize_t pos, object o)
  41. # Like PyTuple_SetItem(), but does no error checking, and should
  42. # only be used to fill in brand new tuples. Note: This function
  43. # ``steals'' a reference to o.
  44. int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize) except -1
  45. # Can be used to resize a tuple. newsize will be the new length of
  46. # the tuple. Because tuples are supposed to be immutable, this
  47. # should only be used if there is only one reference to the
  48. # object. Do not use this if the tuple may already be known to
  49. # some other part of the code. The tuple will always grow or
  50. # shrink at the end. Think of this as destroying the old tuple and
  51. # creating a new one, only more efficiently. Returns 0 on
  52. # success. Client code should never assume that the resulting
  53. # value of *p will be the same as before calling this function. If
  54. # the object referenced by *p is replaced, the original *p is
  55. # destroyed. On failure, returns -1 and sets *p to NULL, and
  56. # raises MemoryError or SystemError.