1 #ifndef Py_CPYTHON_TUPLEOBJECT_H
2 # error "this header file must not be included directly"
3 #endif
4
5 typedef struct {
6 PyObject_VAR_HEAD
7 /* ob_item contains space for 'ob_size' elements.
8 Items must normally not be NULL, except during construction when
9 the tuple is not yet visible outside the function that builds it. */
10 PyObject *ob_item[1];
11 } PyTupleObject;
12
13 PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, Py_ssize_t);
14
15 /* Cast argument to PyTupleObject* type. */
16 #define _PyTuple_CAST(op) \
17 (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
18
19 // Macros and static inline functions, trading safety for speed
20
PyTuple_GET_SIZE(PyObject * op)21 static inline Py_ssize_t PyTuple_GET_SIZE(PyObject *op) {
22 PyTupleObject *tuple = _PyTuple_CAST(op);
23 return Py_SIZE(tuple);
24 }
25 #define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
26
27 #define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
28
29 /* Function *only* to be used to fill in brand new tuples */
30 static inline void
PyTuple_SET_ITEM(PyObject * op,Py_ssize_t index,PyObject * value)31 PyTuple_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
32 PyTupleObject *tuple = _PyTuple_CAST(op);
33 assert(0 <= index);
34 assert(index < Py_SIZE(tuple));
35 tuple->ob_item[index] = value;
36 }
37 #define PyTuple_SET_ITEM(op, index, value) \
38 PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
39