Chris@87: Chris@87: /* Tuple object interface */ Chris@87: Chris@87: #ifndef Py_TUPLEOBJECT_H Chris@87: #define Py_TUPLEOBJECT_H Chris@87: #ifdef __cplusplus Chris@87: extern "C" { Chris@87: #endif Chris@87: Chris@87: /* Chris@87: Another generally useful object type is a tuple of object pointers. Chris@87: For Python, this is an immutable type. C code can change the tuple items Chris@87: (but not their number), and even use tuples are general-purpose arrays of Chris@87: object references, but in general only brand new tuples should be mutated, Chris@87: not ones that might already have been exposed to Python code. Chris@87: Chris@87: *** WARNING *** PyTuple_SetItem does not increment the new item's reference Chris@87: count, but does decrement the reference count of the item it replaces, Chris@87: if not nil. It does *decrement* the reference count if it is *not* Chris@87: inserted in the tuple. Similarly, PyTuple_GetItem does not increment the Chris@87: returned item's reference count. Chris@87: */ Chris@87: Chris@87: typedef struct { Chris@87: PyObject_VAR_HEAD Chris@87: PyObject *ob_item[1]; Chris@87: Chris@87: /* ob_item contains space for 'ob_size' elements. Chris@87: * Items must normally not be NULL, except during construction when Chris@87: * the tuple is not yet visible outside the function that builds it. Chris@87: */ Chris@87: } PyTupleObject; Chris@87: Chris@87: PyAPI_DATA(PyTypeObject) PyTuple_Type; Chris@87: Chris@87: #define PyTuple_Check(op) \ Chris@87: PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS) Chris@87: #define PyTuple_CheckExact(op) (Py_TYPE(op) == &PyTuple_Type) Chris@87: Chris@87: PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size); Chris@87: PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *); Chris@87: PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, Py_ssize_t); Chris@87: PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *); Chris@87: PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); Chris@87: PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, Py_ssize_t); Chris@87: PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...); Chris@87: PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *); Chris@87: Chris@87: /* Macro, trading safety for speed */ Chris@87: #define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i]) Chris@87: #define PyTuple_GET_SIZE(op) Py_SIZE(op) Chris@87: Chris@87: /* Macro, *only* to be used to fill in brand new tuples */ Chris@87: #define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v) Chris@87: Chris@87: PyAPI_FUNC(int) PyTuple_ClearFreeList(void); Chris@87: Chris@87: #ifdef __cplusplus Chris@87: } Chris@87: #endif Chris@87: #endif /* !Py_TUPLEOBJECT_H */