blob: acfac8b2e96f33b0e2170c08339f10baaae86314 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00002Copyright (c) 2000, BeOpen.com.
3Copyright (c) 1995-2000, Corporation for National Research Initiatives.
4Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
5All rights reserved.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00006
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00007See the file "Misc/COPYRIGHT" for information on usage and
8redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00009******************************************************************/
10
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000011/* Tuple object interface */
12
Fred Drake3cf4d2b2000-07-09 00:55:06 +000013#ifndef Py_TUPLEOBJECT_H
14#define Py_TUPLEOBJECT_H
15#ifdef __cplusplus
16extern "C" {
17#endif
18
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000019/*
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000020Another generally useful object type is an tuple of object pointers.
21This is a mutable type: the tuple items can be changed (but not their
22number). Out-of-range indices or non-tuple objects are ignored.
23
Guido van Rossumcaa63801995-01-12 11:45:45 +000024*** WARNING *** PyTuple_SetItem does not increment the new item's reference
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000025count, but does decrement the reference count of the item it replaces,
26if not nil. It does *decrement* the reference count if it is *not*
Guido van Rossumcaa63801995-01-12 11:45:45 +000027inserted in the tuple. Similarly, PyTuple_GetItem does not increment the
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000028returned item's reference count.
29*/
30
Guido van Rossum3f5da241990-12-20 15:06:42 +000031typedef struct {
Fred Drake3cf4d2b2000-07-09 00:55:06 +000032 PyObject_VAR_HEAD
33 PyObject *ob_item[1];
Guido van Rossumcaa63801995-01-12 11:45:45 +000034} PyTupleObject;
Guido van Rossum3f5da241990-12-20 15:06:42 +000035
Sjoerd Mullender107c7471995-04-25 11:53:24 +000036extern DL_IMPORT(PyTypeObject) PyTuple_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000037
Guido van Rossumcaa63801995-01-12 11:45:45 +000038#define PyTuple_Check(op) ((op)->ob_type == &PyTuple_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000039
Fred Drake3cf4d2b2000-07-09 00:55:06 +000040extern DL_IMPORT(PyObject *) PyTuple_New(int size);
41extern DL_IMPORT(int) PyTuple_Size(PyObject *);
42extern DL_IMPORT(PyObject *) PyTuple_GetItem(PyObject *, int);
43extern DL_IMPORT(int) PyTuple_SetItem(PyObject *, int, PyObject *);
44extern DL_IMPORT(PyObject *) PyTuple_GetSlice(PyObject *, int, int);
45extern DL_IMPORT(int) _PyTuple_Resize(PyObject **, int, int);
Guido van Rossum3f5da241990-12-20 15:06:42 +000046
47/* Macro, trading safety for speed */
Guido van Rossum599de5a1995-03-09 12:10:16 +000048#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
Barry Warsaw9c5494a1997-01-06 22:44:27 +000049#define PyTuple_GET_SIZE(op) (((PyTupleObject *)(op))->ob_size)
Guido van Rossum599de5a1995-03-09 12:10:16 +000050
51/* Macro, *only* to be used to fill in brand new tuples */
52#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
Guido van Rossuma3309961993-07-28 09:05:47 +000053
54#ifdef __cplusplus
55}
56#endif
57#endif /* !Py_TUPLEOBJECT_H */