Debian Codegraph @

Include/cpython/tupleobject.h

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