blob: e6f008ed1fa02105cdc12707d4d5594ad1de283b [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_LISTOBJECT_H
2#define Py_LISTOBJECT_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossumf70e43a1991-02-19 12:39:46 +00007/***********************************************************
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00008Copyright (c) 2000, BeOpen.com.
9Copyright (c) 1995-2000, Corporation for National Research Initiatives.
10Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
11All rights reserved.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000012
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000013See the file "Misc/COPYRIGHT" for information on usage and
14redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000015******************************************************************/
16
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000017/* List object interface */
18
19/*
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000020Another generally useful object type is an list of object pointers.
21This is a mutable type: the list items can be changed, and items can be
22added or removed. Out-of-range indices or non-list objects are ignored.
23
Guido van Rossumcaa63801995-01-12 11:45:45 +000024*** WARNING *** PyList_SetItem does not increment the new item's reference
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000025count, but does decrement the reference count of the item it replaces,
26if not nil. It does *decrement* the reference count if it is *not*
Guido van Rossumcaa63801995-01-12 11:45:45 +000027inserted in the list. Similarly, PyList_GetItem does not increment the
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000028returned item's reference count.
29*/
30
Guido van Rossum3f5da241990-12-20 15:06:42 +000031typedef struct {
Guido van Rossumcaa63801995-01-12 11:45:45 +000032 PyObject_VAR_HEAD
33 PyObject **ob_item;
34} PyListObject;
Guido van Rossum3f5da241990-12-20 15:06:42 +000035
Guido van Rossum051ab121995-02-27 10:17:52 +000036extern DL_IMPORT(PyTypeObject) PyList_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000037
Guido van Rossumcaa63801995-01-12 11:45:45 +000038#define PyList_Check(op) ((op)->ob_type == &PyList_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000039
Guido van Rossum43466ec1998-12-04 18:48:25 +000040extern DL_IMPORT(PyObject *) PyList_New Py_PROTO((int size));
41extern DL_IMPORT(int) PyList_Size Py_PROTO((PyObject *));
42extern DL_IMPORT(PyObject *) PyList_GetItem Py_PROTO((PyObject *, int));
43extern DL_IMPORT(int) PyList_SetItem Py_PROTO((PyObject *, int, PyObject *));
44extern DL_IMPORT(int) PyList_Insert Py_PROTO((PyObject *, int, PyObject *));
45extern DL_IMPORT(int) PyList_Append Py_PROTO((PyObject *, PyObject *));
46extern DL_IMPORT(PyObject *) PyList_GetSlice Py_PROTO((PyObject *, int, int));
47extern DL_IMPORT(int) PyList_SetSlice Py_PROTO((PyObject *, int, int, PyObject *));
48extern DL_IMPORT(int) PyList_Sort Py_PROTO((PyObject *));
49extern DL_IMPORT(int) PyList_Reverse Py_PROTO((PyObject *));
50extern DL_IMPORT(PyObject *) PyList_AsTuple Py_PROTO((PyObject *));
Guido van Rossum3f5da241990-12-20 15:06:42 +000051
52/* Macro, trading safety for speed */
Barry Warsaw1f2bd071997-01-06 22:42:00 +000053#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
Guido van Rossuma937d141998-04-24 18:22:02 +000054#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
Barry Warsaw1f2bd071997-01-06 22:42:00 +000055#define PyList_GET_SIZE(op) (((PyListObject *)(op))->ob_size)
Guido van Rossuma3309961993-07-28 09:05:47 +000056
57#ifdef __cplusplus
58}
59#endif
60#endif /* !Py_LISTOBJECT_H */