blob: 1befe86de26aab3a1f2e47c30418910fbd914570 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002/* List object interface */
3
4/*
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00005Another generally useful object type is an list of object pointers.
6This is a mutable type: the list items can be changed, and items can be
7added or removed. Out-of-range indices or non-list objects are ignored.
8
Guido van Rossumcaa63801995-01-12 11:45:45 +00009*** WARNING *** PyList_SetItem does not increment the new item's reference
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000010count, but does decrement the reference count of the item it replaces,
11if not nil. It does *decrement* the reference count if it is *not*
Guido van Rossumcaa63801995-01-12 11:45:45 +000012inserted in the list. Similarly, PyList_GetItem does not increment the
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000013returned item's reference count.
14*/
15
Fred Drakeea9cb5a2000-07-09 00:20:36 +000016#ifndef Py_LISTOBJECT_H
17#define Py_LISTOBJECT_H
18#ifdef __cplusplus
19extern "C" {
20#endif
21
Guido van Rossum3f5da241990-12-20 15:06:42 +000022typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000023 PyObject_VAR_HEAD
24 PyObject **ob_item;
Guido van Rossumcaa63801995-01-12 11:45:45 +000025} PyListObject;
Guido van Rossum3f5da241990-12-20 15:06:42 +000026
Guido van Rossum051ab121995-02-27 10:17:52 +000027extern DL_IMPORT(PyTypeObject) PyList_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000028
Tim Peters6d6c1a32001-08-02 04:15:00 +000029#define PyList_Check(op) PyObject_TypeCheck(op, &PyList_Type)
Tim Petersb1c46982001-10-05 20:41:38 +000030#define PyList_CheckExact(op) ((op)->ob_type == &PyList_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000031
Fred Drakeea9cb5a2000-07-09 00:20:36 +000032extern DL_IMPORT(PyObject *) PyList_New(int size);
33extern DL_IMPORT(int) PyList_Size(PyObject *);
34extern DL_IMPORT(PyObject *) PyList_GetItem(PyObject *, int);
35extern DL_IMPORT(int) PyList_SetItem(PyObject *, int, PyObject *);
36extern DL_IMPORT(int) PyList_Insert(PyObject *, int, PyObject *);
37extern DL_IMPORT(int) PyList_Append(PyObject *, PyObject *);
38extern DL_IMPORT(PyObject *) PyList_GetSlice(PyObject *, int, int);
39extern DL_IMPORT(int) PyList_SetSlice(PyObject *, int, int, PyObject *);
40extern DL_IMPORT(int) PyList_Sort(PyObject *);
41extern DL_IMPORT(int) PyList_Reverse(PyObject *);
42extern DL_IMPORT(PyObject *) PyList_AsTuple(PyObject *);
Guido van Rossum3f5da241990-12-20 15:06:42 +000043
44/* Macro, trading safety for speed */
Barry Warsaw1f2bd071997-01-06 22:42:00 +000045#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
Guido van Rossuma937d141998-04-24 18:22:02 +000046#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
Barry Warsaw1f2bd071997-01-06 22:42:00 +000047#define PyList_GET_SIZE(op) (((PyListObject *)(op))->ob_size)
Guido van Rossuma3309961993-07-28 09:05:47 +000048
49#ifdef __cplusplus
50}
51#endif
52#endif /* !Py_LISTOBJECT_H */