blob: 9a614846ff61be98805dff18d73347e6f5d40b04 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002/* Tuple object interface */
3
Fred Drake3cf4d2b2000-07-09 00:55:06 +00004#ifndef Py_TUPLEOBJECT_H
5#define Py_TUPLEOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000010/*
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000011Another generally useful object type is an tuple of object pointers.
12This is a mutable type: the tuple items can be changed (but not their
13number). Out-of-range indices or non-tuple objects are ignored.
14
Guido van Rossumcaa63801995-01-12 11:45:45 +000015*** WARNING *** PyTuple_SetItem does not increment the new item's reference
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000016count, but does decrement the reference count of the item it replaces,
17if not nil. It does *decrement* the reference count if it is *not*
Guido van Rossumcaa63801995-01-12 11:45:45 +000018inserted in the tuple. Similarly, PyTuple_GetItem does not increment the
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000019returned item's reference count.
20*/
21
Guido van Rossum3f5da241990-12-20 15:06:42 +000022typedef struct {
Fred Drake3cf4d2b2000-07-09 00:55:06 +000023 PyObject_VAR_HEAD
24 PyObject *ob_item[1];
Guido van Rossumcaa63801995-01-12 11:45:45 +000025} PyTupleObject;
Guido van Rossum3f5da241990-12-20 15:06:42 +000026
Sjoerd Mullender107c7471995-04-25 11:53:24 +000027extern DL_IMPORT(PyTypeObject) PyTuple_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000028
Guido van Rossumcaa63801995-01-12 11:45:45 +000029#define PyTuple_Check(op) ((op)->ob_type == &PyTuple_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000030
Fred Drake3cf4d2b2000-07-09 00:55:06 +000031extern DL_IMPORT(PyObject *) PyTuple_New(int size);
32extern DL_IMPORT(int) PyTuple_Size(PyObject *);
33extern DL_IMPORT(PyObject *) PyTuple_GetItem(PyObject *, int);
34extern DL_IMPORT(int) PyTuple_SetItem(PyObject *, int, PyObject *);
35extern DL_IMPORT(PyObject *) PyTuple_GetSlice(PyObject *, int, int);
36extern DL_IMPORT(int) _PyTuple_Resize(PyObject **, int, int);
Guido van Rossum3f5da241990-12-20 15:06:42 +000037
38/* Macro, trading safety for speed */
Guido van Rossum599de5a1995-03-09 12:10:16 +000039#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
Barry Warsaw9c5494a1997-01-06 22:44:27 +000040#define PyTuple_GET_SIZE(op) (((PyTupleObject *)(op))->ob_size)
Guido van Rossum599de5a1995-03-09 12:10:16 +000041
42/* Macro, *only* to be used to fill in brand new tuples */
43#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
Guido van Rossuma3309961993-07-28 09:05:47 +000044
45#ifdef __cplusplus
46}
47#endif
48#endif /* !Py_TUPLEOBJECT_H */