Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | #ifndef Py_TUPLEOBJECT_H |
2 | #define Py_TUPLEOBJECT_H | |
3 | #ifdef __cplusplus | |
4 | extern "C" { | |
5 | #endif | |
6 | ||
7 | /* | |
8 | Another generally useful object type is a tuple of object pointers. | |
9 | For Python, this is an immutable type. C code can change the tuple items | |
10 | (but not their number), and even use tuples are general-purpose arrays of | |
11 | object references, but in general only brand new tuples should be mutated, | |
12 | not ones that might already have been exposed to Python code. | |
13 | ||
14 | *** WARNING *** PyTuple_SetItem does not increment the new item's reference | |
15 | count, but does decrement the reference count of the item it replaces, | |
16 | if not nil. It does *decrement* the reference count if it is *not* | |
17 | inserted in the tuple. Similarly, PyTuple_GetItem does not increment the | |
18 | returned item's reference count. | |
19 | */ | |
20 | ||
21 | typedef struct { | |
22 | PyObject_VAR_HEAD | |
23 | PyObject *ob_item[1]; | |
24 | ||
25 | /* ob_item contains space for 'ob_size' elements. | |
26 | * Items must normally not be NULL, except during construction when | |
27 | * the tuple is not yet visible outside the function that builds it. | |
28 | */ | |
29 | } PyTupleObject; | |
30 | ||
31 | PyAPI_DATA(PyTypeObject) PyTuple_Type; | |
32 | ||
33 | #define PyTuple_Check(op) PyObject_TypeCheck(op, &PyTuple_Type) | |
34 | #define PyTuple_CheckExact(op) ((op)->ob_type == &PyTuple_Type) | |
35 | ||
36 | PyAPI_FUNC(PyObject *) PyTuple_New(int size); | |
37 | PyAPI_FUNC(int) PyTuple_Size(PyObject *); | |
38 | PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, int); | |
39 | PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, int, PyObject *); | |
40 | PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, int, int); | |
41 | PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, int); | |
42 | PyAPI_FUNC(PyObject *) PyTuple_Pack(int, ...); | |
43 | ||
44 | /* Macro, trading safety for speed */ | |
45 | #define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i]) | |
46 | #define PyTuple_GET_SIZE(op) (((PyTupleObject *)(op))->ob_size) | |
47 | ||
48 | /* Macro, *only* to be used to fill in brand new tuples */ | |
49 | #define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v) | |
50 | ||
51 | #ifdef __cplusplus | |
52 | } | |
53 | #endif | |
54 | #endif /* !Py_TUPLEOBJECT_H */ |