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