| 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 | PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *); |
| 15 | |
| 16 | /* Cast argument to PyTupleObject* type. */ |
| 17 | #define _PyTuple_CAST(op) \ |
| 18 | (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op))) |
| 19 | |
| 20 | // Macros and static inline functions, trading safety for speed |
| 21 | |
| 22 | static inline Py_ssize_t PyTuple_GET_SIZE(PyObject *op) { |
| 23 | PyTupleObject *tuple = _PyTuple_CAST(op); |
| 24 | return Py_SIZE(tuple); |
| 25 | } |
| 26 | #define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op)) |
| 27 | |
| 28 | #define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)]) |
| 29 | |
| 30 | /* Function *only* to be used to fill in brand new tuples */ |
| 31 | static inline void |
| 32 | PyTuple_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) { |
| 33 | PyTupleObject *tuple = _PyTuple_CAST(op); |
| 34 | tuple->ob_item[index] = value; |
| 35 | } |
| 36 | #define PyTuple_SET_ITEM(op, index, value) \ |
| 37 | PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value)) |
| 38 | |
| 39 | PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out); |
| 40 | |