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