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 | /* List object interface */ |
| 3 | |
| 4 | /* |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 5 | Another generally useful object type is an list of object pointers. |
| 6 | This is a mutable type: the list items can be changed, and items can be |
| 7 | added or removed. Out-of-range indices or non-list objects are ignored. |
| 8 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 9 | *** WARNING *** PyList_SetItem does not increment the new item's reference |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 10 | count, but does decrement the reference count of the item it replaces, |
| 11 | 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] | 12 | inserted in the list. Similarly, PyList_GetItem does not increment the |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 13 | returned item's reference count. |
| 14 | */ |
| 15 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 16 | #ifndef Py_LISTOBJECT_H |
| 17 | #define Py_LISTOBJECT_H |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 22 | typedef struct { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 23 | PyObject_VAR_HEAD |
| 24 | PyObject **ob_item; |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 25 | } PyListObject; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 26 | |
Guido van Rossum | 051ab12 | 1995-02-27 10:17:52 +0000 | [diff] [blame] | 27 | extern DL_IMPORT(PyTypeObject) PyList_Type; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 28 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 29 | #define PyList_Check(op) ((op)->ob_type == &PyList_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 30 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 31 | extern DL_IMPORT(PyObject *) PyList_New(int size); |
| 32 | extern DL_IMPORT(int) PyList_Size(PyObject *); |
| 33 | extern DL_IMPORT(PyObject *) PyList_GetItem(PyObject *, int); |
| 34 | extern DL_IMPORT(int) PyList_SetItem(PyObject *, int, PyObject *); |
| 35 | extern DL_IMPORT(int) PyList_Insert(PyObject *, int, PyObject *); |
| 36 | extern DL_IMPORT(int) PyList_Append(PyObject *, PyObject *); |
| 37 | extern DL_IMPORT(PyObject *) PyList_GetSlice(PyObject *, int, int); |
| 38 | extern DL_IMPORT(int) PyList_SetSlice(PyObject *, int, int, PyObject *); |
| 39 | extern DL_IMPORT(int) PyList_Sort(PyObject *); |
| 40 | extern DL_IMPORT(int) PyList_Reverse(PyObject *); |
| 41 | extern DL_IMPORT(PyObject *) PyList_AsTuple(PyObject *); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 42 | |
| 43 | /* Macro, trading safety for speed */ |
Barry Warsaw | 1f2bd07 | 1997-01-06 22:42:00 +0000 | [diff] [blame] | 44 | #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i]) |
Guido van Rossum | a937d14 | 1998-04-24 18:22:02 +0000 | [diff] [blame] | 45 | #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v)) |
Barry Warsaw | 1f2bd07 | 1997-01-06 22:42:00 +0000 | [diff] [blame] | 46 | #define PyList_GET_SIZE(op) (((PyListObject *)(op))->ob_size) |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 47 | |
| 48 | #ifdef __cplusplus |
| 49 | } |
| 50 | #endif |
| 51 | #endif /* !Py_LISTOBJECT_H */ |