Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2 | /* Tuple object interface */ |
| 3 | |
Fred Drake | 3cf4d2b | 2000-07-09 00:55:06 +0000 | [diff] [blame] | 4 | #ifndef Py_TUPLEOBJECT_H |
| 5 | #define Py_TUPLEOBJECT_H |
| 6 | #ifdef __cplusplus |
| 7 | extern "C" { |
| 8 | #endif |
| 9 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 10 | /* |
Armin Rigo | 89a3946 | 2004-10-28 16:32:00 +0000 | [diff] [blame] | 11 | Another generally useful object type is a tuple of object pointers. |
| 12 | For Python, this is an immutable type. C code can change the tuple items |
| 13 | (but not their number), and even use tuples are general-purpose arrays of |
| 14 | object references, but in general only brand new tuples should be mutated, |
| 15 | not ones that might already have been exposed to Python code. |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 17 | *** WARNING *** PyTuple_SetItem does not increment the new item's reference |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 18 | count, but does decrement the reference count of the item it replaces, |
| 19 | if not nil. It does *decrement* the reference count if it is *not* |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 20 | inserted in the tuple. Similarly, PyTuple_GetItem does not increment the |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 21 | returned item's reference count. |
| 22 | */ |
| 23 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 24 | #ifndef Py_LIMITED_API |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 25 | typedef struct { |
Fred Drake | 3cf4d2b | 2000-07-09 00:55:06 +0000 | [diff] [blame] | 26 | PyObject_VAR_HEAD |
| 27 | PyObject *ob_item[1]; |
Armin Rigo | 89a3946 | 2004-10-28 16:32:00 +0000 | [diff] [blame] | 28 | |
| 29 | /* ob_item contains space for 'ob_size' elements. |
| 30 | * Items must normally not be NULL, except during construction when |
| 31 | * the tuple is not yet visible outside the function that builds it. |
| 32 | */ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 33 | } PyTupleObject; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 34 | #endif |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 35 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 36 | PyAPI_DATA(PyTypeObject) PyTuple_Type; |
Christian Heimes | a22e8bd | 2007-11-29 22:35:39 +0000 | [diff] [blame] | 37 | PyAPI_DATA(PyTypeObject) PyTupleIter_Type; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 38 | |
Thomas Wouters | 27d517b | 2007-02-25 20:39:11 +0000 | [diff] [blame] | 39 | #define PyTuple_Check(op) \ |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 40 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS) |
| 41 | #define PyTuple_CheckExact(op) (Py_TYPE(op) == &PyTuple_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 42 | |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 43 | PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size); |
| 44 | PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *); |
| 45 | PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, Py_ssize_t); |
| 46 | PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *); |
| 47 | PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 48 | #ifndef Py_LIMITED_API |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 49 | PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, Py_ssize_t); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 50 | #endif |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 51 | PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 52 | #ifndef Py_LIMITED_API |
Antoine Pitrou | 3a652b1 | 2009-03-23 18:52:06 +0000 | [diff] [blame] | 53 | PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 54 | #endif |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 55 | |
| 56 | /* Macro, trading safety for speed */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 57 | #ifndef Py_LIMITED_API |
Guido van Rossum | 599de5a | 1995-03-09 12:10:16 +0000 | [diff] [blame] | 58 | #define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i]) |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 59 | #define PyTuple_GET_SIZE(op) Py_SIZE(op) |
Guido van Rossum | 599de5a | 1995-03-09 12:10:16 +0000 | [diff] [blame] | 60 | |
| 61 | /* Macro, *only* to be used to fill in brand new tuples */ |
| 62 | #define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v) |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 63 | #endif |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 64 | |
Christian Heimes | a156e09 | 2008-02-16 07:38:31 +0000 | [diff] [blame] | 65 | PyAPI_FUNC(int) PyTuple_ClearFreeList(void); |
| 66 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 67 | #ifdef __cplusplus |
| 68 | } |
| 69 | #endif |
| 70 | #endif /* !Py_TUPLEOBJECT_H */ |