blob: 1630efa81a757b825847e8e4ec4a7a2e2c57f53e [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_TUPLEOBJECT_H
2#define Py_TUPLEOBJECT_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossumf70e43a1991-02-19 12:39:46 +00007/***********************************************************
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00008Copyright (c) 2000, BeOpen.com.
9Copyright (c) 1995-2000, Corporation for National Research Initiatives.
10Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
11All rights reserved.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000012
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000013See the file "Misc/COPYRIGHT" for information on usage and
14redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000015******************************************************************/
16
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000017/* Tuple object interface */
18
19/*
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 {
Guido van Rossumcaa63801995-01-12 11:45:45 +000032 PyObject_VAR_HEAD
33 PyObject *ob_item[1];
34} 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
Guido van Rossum43466ec1998-12-04 18:48:25 +000040extern DL_IMPORT(PyObject *) PyTuple_New Py_PROTO((int size));
41extern DL_IMPORT(int) PyTuple_Size Py_PROTO((PyObject *));
42extern DL_IMPORT(PyObject *) PyTuple_GetItem Py_PROTO((PyObject *, int));
43extern DL_IMPORT(int) PyTuple_SetItem Py_PROTO((PyObject *, int, PyObject *));
44extern DL_IMPORT(PyObject *) PyTuple_GetSlice Py_PROTO((PyObject *, int, int));
45extern DL_IMPORT(int) _PyTuple_Resize Py_PROTO((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 */