Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 2 | Copyright (c) 2000, BeOpen.com. |
| 3 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 4 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 5 | All rights reserved. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 7 | See the file "Misc/COPYRIGHT" for information on usage and |
| 8 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 9 | ******************************************************************/ |
| 10 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 11 | /* Tuple object interface */ |
| 12 | |
Fred Drake | 3cf4d2b | 2000-07-09 00:55:06 +0000 | [diff] [blame] | 13 | #ifndef Py_TUPLEOBJECT_H |
| 14 | #define Py_TUPLEOBJECT_H |
| 15 | #ifdef __cplusplus |
| 16 | extern "C" { |
| 17 | #endif |
| 18 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 19 | /* |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 20 | Another generally useful object type is an tuple of object pointers. |
| 21 | This is a mutable type: the tuple items can be changed (but not their |
| 22 | number). Out-of-range indices or non-tuple objects are ignored. |
| 23 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 24 | *** WARNING *** PyTuple_SetItem does not increment the new item's reference |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 25 | count, but does decrement the reference count of the item it replaces, |
| 26 | 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] | 27 | inserted in the tuple. Similarly, PyTuple_GetItem does not increment the |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 28 | returned item's reference count. |
| 29 | */ |
| 30 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 31 | typedef struct { |
Fred Drake | 3cf4d2b | 2000-07-09 00:55:06 +0000 | [diff] [blame] | 32 | PyObject_VAR_HEAD |
| 33 | PyObject *ob_item[1]; |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 34 | } PyTupleObject; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 35 | |
Sjoerd Mullender | 107c747 | 1995-04-25 11:53:24 +0000 | [diff] [blame] | 36 | extern DL_IMPORT(PyTypeObject) PyTuple_Type; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 37 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 38 | #define PyTuple_Check(op) ((op)->ob_type == &PyTuple_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 39 | |
Fred Drake | 3cf4d2b | 2000-07-09 00:55:06 +0000 | [diff] [blame] | 40 | extern DL_IMPORT(PyObject *) PyTuple_New(int size); |
| 41 | extern DL_IMPORT(int) PyTuple_Size(PyObject *); |
| 42 | extern DL_IMPORT(PyObject *) PyTuple_GetItem(PyObject *, int); |
| 43 | extern DL_IMPORT(int) PyTuple_SetItem(PyObject *, int, PyObject *); |
| 44 | extern DL_IMPORT(PyObject *) PyTuple_GetSlice(PyObject *, int, int); |
| 45 | extern DL_IMPORT(int) _PyTuple_Resize(PyObject **, int, int); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 46 | |
| 47 | /* Macro, trading safety for speed */ |
Guido van Rossum | 599de5a | 1995-03-09 12:10:16 +0000 | [diff] [blame] | 48 | #define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i]) |
Barry Warsaw | 9c5494a | 1997-01-06 22:44:27 +0000 | [diff] [blame] | 49 | #define PyTuple_GET_SIZE(op) (((PyTupleObject *)(op))->ob_size) |
Guido van Rossum | 599de5a | 1995-03-09 12:10:16 +0000 | [diff] [blame] | 50 | |
| 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 Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 53 | |
| 54 | #ifdef __cplusplus |
| 55 | } |
| 56 | #endif |
| 57 | #endif /* !Py_TUPLEOBJECT_H */ |