blob: 2a8a25525d1d7bf660ab7ed55592a4714ac6c5af [file] [log] [blame]
Victor Stinnerbec41862020-02-07 09:20:22 +01001/* List object interface
Guido van Rossumf70e43a1991-02-19 12:39:46 +00002
Victor Stinnerbec41862020-02-07 09:20:22 +01003 Another generally useful object type is a list of object pointers.
4 This is a mutable type: the list items can be changed, and items can be
5 added or removed. Out-of-range indices or non-list objects are ignored.
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00006
Victor Stinnerbec41862020-02-07 09:20:22 +01007 WARNING: PyList_SetItem does not increment the new item's reference count,
8 but does decrement the reference count of the item it replaces, if not nil.
9 It does *decrement* the reference count if it is *not* inserted in the list.
10 Similarly, PyList_GetItem does not increment the returned item's reference
11 count.
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000012*/
13
Fred Drakeea9cb5a2000-07-09 00:20:36 +000014#ifndef Py_LISTOBJECT_H
15#define Py_LISTOBJECT_H
16#ifdef __cplusplus
17extern "C" {
18#endif
19
Mark Hammond91a681d2002-08-12 07:21:58 +000020PyAPI_DATA(PyTypeObject) PyList_Type;
Christian Heimesa22e8bd2007-11-29 22:35:39 +000021PyAPI_DATA(PyTypeObject) PyListIter_Type;
22PyAPI_DATA(PyTypeObject) PyListRevIter_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000023
Thomas Wouters27d517b2007-02-25 20:39:11 +000024#define PyList_Check(op) \
Benjamin Peterson1a2cf9a2014-05-26 15:12:28 -070025 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
Dong-hee Nad905df72020-02-14 02:37:17 +090026#define PyList_CheckExact(op) Py_IS_TYPE(op, &PyList_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000027
Martin v. Löwis18e16552006-02-15 17:27:45 +000028PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);
29PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *);
Victor Stinnerbec41862020-02-07 09:20:22 +010030
Martin v. Löwis18e16552006-02-15 17:27:45 +000031PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t);
32PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *);
33PyAPI_FUNC(int) PyList_Insert(PyObject *, Py_ssize_t, PyObject *);
Mark Hammond91a681d2002-08-12 07:21:58 +000034PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *);
Victor Stinnerbec41862020-02-07 09:20:22 +010035
Martin v. Löwis18e16552006-02-15 17:27:45 +000036PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
37PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
Victor Stinnerbec41862020-02-07 09:20:22 +010038
Mark Hammond91a681d2002-08-12 07:21:58 +000039PyAPI_FUNC(int) PyList_Sort(PyObject *);
40PyAPI_FUNC(int) PyList_Reverse(PyObject *);
41PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *);
Antoine Pitrou9a812cb2011-11-15 00:00:12 +010042
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000043#ifndef Py_LIMITED_API
Victor Stinnerbec41862020-02-07 09:20:22 +010044# define Py_CPYTHON_LISTOBJECT_H
45# include "cpython/listobject.h"
46# undef Py_CPYTHON_LISTOBJECT_H
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000047#endif
Guido van Rossuma3309961993-07-28 09:05:47 +000048
49#ifdef __cplusplus
50}
51#endif
52#endif /* !Py_LISTOBJECT_H */