blob: 84478c2e4c7f3cfc205b17b507daf97da838421d [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 Rossum5799b521995-01-04 19:06:22 +00008Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
9The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000010
11 All Rights Reserved
12
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000013Copyright (c) 2000, BeOpen.com.
14Copyright (c) 1995-2000, Corporation for National Research Initiatives.
15Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
16All rights reserved.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000017
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000018See the file "Misc/COPYRIGHT" for information on usage and
19redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000020
21******************************************************************/
22
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000023/* List object interface */
24
25/*
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000026Another generally useful object type is an list of object pointers.
27This is a mutable type: the list items can be changed, and items can be
28added or removed. Out-of-range indices or non-list objects are ignored.
29
Guido van Rossumcaa63801995-01-12 11:45:45 +000030*** WARNING *** PyList_SetItem does not increment the new item's reference
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000031count, but does decrement the reference count of the item it replaces,
32if not nil. It does *decrement* the reference count if it is *not*
Guido van Rossumcaa63801995-01-12 11:45:45 +000033inserted in the list. Similarly, PyList_GetItem does not increment the
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000034returned item's reference count.
35*/
36
Guido van Rossum3f5da241990-12-20 15:06:42 +000037typedef struct {
Guido van Rossumcaa63801995-01-12 11:45:45 +000038 PyObject_VAR_HEAD
39 PyObject **ob_item;
40} PyListObject;
Guido van Rossum3f5da241990-12-20 15:06:42 +000041
Guido van Rossum051ab121995-02-27 10:17:52 +000042extern DL_IMPORT(PyTypeObject) PyList_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000043
Guido van Rossumcaa63801995-01-12 11:45:45 +000044#define PyList_Check(op) ((op)->ob_type == &PyList_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000045
Guido van Rossum43466ec1998-12-04 18:48:25 +000046extern DL_IMPORT(PyObject *) PyList_New Py_PROTO((int size));
47extern DL_IMPORT(int) PyList_Size Py_PROTO((PyObject *));
48extern DL_IMPORT(PyObject *) PyList_GetItem Py_PROTO((PyObject *, int));
49extern DL_IMPORT(int) PyList_SetItem Py_PROTO((PyObject *, int, PyObject *));
50extern DL_IMPORT(int) PyList_Insert Py_PROTO((PyObject *, int, PyObject *));
51extern DL_IMPORT(int) PyList_Append Py_PROTO((PyObject *, PyObject *));
52extern DL_IMPORT(PyObject *) PyList_GetSlice Py_PROTO((PyObject *, int, int));
53extern DL_IMPORT(int) PyList_SetSlice Py_PROTO((PyObject *, int, int, PyObject *));
54extern DL_IMPORT(int) PyList_Sort Py_PROTO((PyObject *));
55extern DL_IMPORT(int) PyList_Reverse Py_PROTO((PyObject *));
56extern DL_IMPORT(PyObject *) PyList_AsTuple Py_PROTO((PyObject *));
Guido van Rossum3f5da241990-12-20 15:06:42 +000057
58/* Macro, trading safety for speed */
Barry Warsaw1f2bd071997-01-06 22:42:00 +000059#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
Guido van Rossuma937d141998-04-24 18:22:02 +000060#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
Barry Warsaw1f2bd071997-01-06 22:42:00 +000061#define PyList_GET_SIZE(op) (((PyListObject *)(op))->ob_size)
Guido van Rossuma3309961993-07-28 09:05:47 +000062
63#ifdef __cplusplus
64}
65#endif
66#endif /* !Py_LISTOBJECT_H */