1 2 /* Tuple object interface */ 3 4 #ifndef Py_TUPLEOBJECT_H 5 #define Py_TUPLEOBJECT_H 6 #ifdef __cplusplus 7 extern "C" { 8 #endif 9 10 /* 11 Another generally useful object type is a tuple of object pointers. 12 For Python, this is an immutable type. C code can change the tuple items 13 (but not their number), and even use tuples are general-purpose arrays of 14 object references, but in general only brand new tuples should be mutated, 15 not ones that might already have been exposed to Python code. 16 17 *** WARNING *** PyTuple_SetItem does not increment the new item's reference 18 count, but does decrement the reference count of the item it replaces, 19 if not nil. It does *decrement* the reference count if it is *not* 20 inserted in the tuple. Similarly, PyTuple_GetItem does not increment the 21 returned item's reference count. 22 */ 23 24 #ifndef Py_LIMITED_API 25 typedef struct { 26 PyObject_VAR_HEAD 27 PyObject *ob_item[1]; 28 29 /* ob_item contains space for 'ob_size' elements. 30 * Items must normally not be NULL, except during construction when 31 * the tuple is not yet visible outside the function that builds it. 32 */ 33 } PyTupleObject; 34 #endif 35 36 PyAPI_DATA(PyTypeObject) PyTuple_Type; 37 PyAPI_DATA(PyTypeObject) PyTupleIter_Type; 38 39 #define PyTuple_Check(op) \ 40 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS) 41 #define PyTuple_CheckExact(op) (Py_TYPE(op) == &PyTuple_Type) 42 43 PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size); 44 PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *); 45 PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, Py_ssize_t); 46 PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *); 47 PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); 48 #ifndef Py_LIMITED_API 49 PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, Py_ssize_t); 50 #endif 51 PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...); 52 #ifndef Py_LIMITED_API 53 PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *); 54 #endif 55 56 /* Macro, trading safety for speed */ 57 #ifndef Py_LIMITED_API 58 #define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i]) 59 #define PyTuple_GET_SIZE(op) Py_SIZE(op) 60 61 /* Macro, *only* to be used to fill in brand new tuples */ 62 #define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v) 63 #endif 64 65 PyAPI_FUNC(int) PyTuple_ClearFreeList(void); 66 #ifndef Py_LIMITED_API 67 PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out); 68 #endif /* Py_LIMITED_API */ 69 70 #ifdef __cplusplus 71 } 72 #endif 73 #endif /* !Py_TUPLEOBJECT_H */ 74