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 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 27 | PyAPI_DATA(PyTypeObject) PyList_Type; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 28 | |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 29 | #define PyList_Check(op) PyObject_TypeCheck(op, &PyList_Type) |
Tim Peters | b1c4698 | 2001-10-05 20:41:38 +0000 | [diff] [blame] | 30 | #define PyList_CheckExact(op) ((op)->ob_type == &PyList_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 31 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 32 | PyAPI_FUNC(PyObject *) PyList_New(int size); |
| 33 | PyAPI_FUNC(int) PyList_Size(PyObject *); |
| 34 | PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, int); |
| 35 | PyAPI_FUNC(int) PyList_SetItem(PyObject *, int, PyObject *); |
| 36 | PyAPI_FUNC(int) PyList_Insert(PyObject *, int, PyObject *); |
| 37 | PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *); |
| 38 | PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, int, int); |
| 39 | PyAPI_FUNC(int) PyList_SetSlice(PyObject *, int, int, PyObject *); |
| 40 | PyAPI_FUNC(int) PyList_Sort(PyObject *); |
| 41 | PyAPI_FUNC(int) PyList_Reverse(PyObject *); |
| 42 | PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 43 | |
| 44 | /* Macro, trading safety for speed */ |
Barry Warsaw | 1f2bd07 | 1997-01-06 22:42:00 +0000 | [diff] [blame] | 45 | #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i]) |
Guido van Rossum | a937d14 | 1998-04-24 18:22:02 +0000 | [diff] [blame] | 46 | #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] | 47 | #define PyList_GET_SIZE(op) (((PyListObject *)(op))->ob_size) |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 48 | |
| 49 | #ifdef __cplusplus |
| 50 | } |
| 51 | #endif |
| 52 | #endif /* !Py_LISTOBJECT_H */ |