Victor Stinner | bec4186 | 2020-02-07 09:20:22 +0100 | [diff] [blame] | 1 | /* List object interface |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 2 | |
Victor Stinner | bec4186 | 2020-02-07 09:20:22 +0100 | [diff] [blame] | 3 | 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 Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 6 | |
Victor Stinner | bec4186 | 2020-02-07 09:20:22 +0100 | [diff] [blame] | 7 | 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 Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 12 | */ |
| 13 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 14 | #ifndef Py_LISTOBJECT_H |
| 15 | #define Py_LISTOBJECT_H |
| 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 20 | PyAPI_DATA(PyTypeObject) PyList_Type; |
Christian Heimes | a22e8bd | 2007-11-29 22:35:39 +0000 | [diff] [blame] | 21 | PyAPI_DATA(PyTypeObject) PyListIter_Type; |
| 22 | PyAPI_DATA(PyTypeObject) PyListRevIter_Type; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 23 | |
Thomas Wouters | 27d517b | 2007-02-25 20:39:11 +0000 | [diff] [blame] | 24 | #define PyList_Check(op) \ |
Benjamin Peterson | 1a2cf9a | 2014-05-26 15:12:28 -0700 | [diff] [blame] | 25 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS) |
Dong-hee Na | d905df7 | 2020-02-14 02:37:17 +0900 | [diff] [blame] | 26 | #define PyList_CheckExact(op) Py_IS_TYPE(op, &PyList_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 27 | |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 28 | PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size); |
| 29 | PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *); |
Victor Stinner | bec4186 | 2020-02-07 09:20:22 +0100 | [diff] [blame] | 30 | |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 31 | PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t); |
| 32 | PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *); |
| 33 | PyAPI_FUNC(int) PyList_Insert(PyObject *, Py_ssize_t, PyObject *); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 34 | PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *); |
Victor Stinner | bec4186 | 2020-02-07 09:20:22 +0100 | [diff] [blame] | 35 | |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 36 | PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); |
| 37 | PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *); |
Victor Stinner | bec4186 | 2020-02-07 09:20:22 +0100 | [diff] [blame] | 38 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 39 | PyAPI_FUNC(int) PyList_Sort(PyObject *); |
| 40 | PyAPI_FUNC(int) PyList_Reverse(PyObject *); |
| 41 | PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *); |
Antoine Pitrou | 9a812cb | 2011-11-15 00:00:12 +0100 | [diff] [blame] | 42 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 43 | #ifndef Py_LIMITED_API |
Victor Stinner | bec4186 | 2020-02-07 09:20:22 +0100 | [diff] [blame] | 44 | # define Py_CPYTHON_LISTOBJECT_H |
| 45 | # include "cpython/listobject.h" |
| 46 | # undef Py_CPYTHON_LISTOBJECT_H |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 47 | #endif |
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 */ |