blob: e796a320192c204466ffca35d27a32fd3d064f5c [file] [log] [blame]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001/* Tuple object interface */
2
Fred Drake3cf4d2b2000-07-09 00:55:06 +00003#ifndef Py_TUPLEOBJECT_H
4#define Py_TUPLEOBJECT_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00009/*
Armin Rigo89a39462004-10-28 16:32:00 +000010Another generally useful object type is a tuple of object pointers.
11For Python, this is an immutable type. C code can change the tuple items
Chrise0720cd2017-12-11 23:59:30 -080012(but not their number), and even use tuples as general-purpose arrays of
Armin Rigo89a39462004-10-28 16:32:00 +000013object references, but in general only brand new tuples should be mutated,
14not ones that might already have been exposed to Python code.
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000015
Guido van Rossumcaa63801995-01-12 11:45:45 +000016*** WARNING *** PyTuple_SetItem does not increment the new item's reference
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000017count, but does decrement the reference count of the item it replaces,
18if not nil. It does *decrement* the reference count if it is *not*
Guido van Rossumcaa63801995-01-12 11:45:45 +000019inserted in the tuple. Similarly, PyTuple_GetItem does not increment the
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000020returned item's reference count.
21*/
22
Mark Hammond91a681d2002-08-12 07:21:58 +000023PyAPI_DATA(PyTypeObject) PyTuple_Type;
Christian Heimesa22e8bd2007-11-29 22:35:39 +000024PyAPI_DATA(PyTypeObject) PyTupleIter_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000025
Thomas Wouters27d517b2007-02-25 20:39:11 +000026#define PyTuple_Check(op) \
Christian Heimes90aa7642007-12-19 02:45:37 +000027 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
Dong-hee Nad905df72020-02-14 02:37:17 +090028#define PyTuple_CheckExact(op) Py_IS_TYPE(op, &PyTuple_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000029
Martin v. Löwis18e16552006-02-15 17:27:45 +000030PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size);
31PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *);
32PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, Py_ssize_t);
33PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);
34PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
Martin v. Löwis18e16552006-02-15 17:27:45 +000035PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);
Guido van Rossuma3309961993-07-28 09:05:47 +000036
David Malcolm49526f42012-06-22 14:55:41 -040037#ifndef Py_LIMITED_API
Victor Stinner54ba5562018-11-28 13:01:32 +010038# define Py_CPYTHON_TUPLEOBJECT_H
39# include "cpython/tupleobject.h"
40# undef Py_CPYTHON_TUPLEOBJECT_H
41#endif
Christian Heimesa156e092008-02-16 07:38:31 +000042
Guido van Rossuma3309961993-07-28 09:05:47 +000043#ifdef __cplusplus
44}
45#endif
46#endif /* !Py_TUPLEOBJECT_H */