| Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 |  | 
| Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2 | /* List object interface */ | 
 | 3 |  | 
 | 4 | /* | 
| Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 5 | Another generally useful object type is an list of object pointers. | 
 | 6 | This is a mutable type: the list items can be changed, and items can be | 
 | 7 | added or removed.  Out-of-range indices or non-list objects are ignored. | 
 | 8 |  | 
| Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 9 | *** WARNING *** PyList_SetItem does not increment the new item's reference | 
| Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 10 | count, but does decrement the reference count of the item it replaces, | 
 | 11 | if not nil.  It does *decrement* the reference count if it is *not* | 
| Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 12 | inserted in the list.  Similarly, PyList_GetItem does not increment the | 
| Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 13 | returned item's reference count. | 
 | 14 | */ | 
 | 15 |  | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 16 | #ifndef Py_LISTOBJECT_H | 
 | 17 | #define Py_LISTOBJECT_H | 
 | 18 | #ifdef __cplusplus | 
 | 19 | extern "C" { | 
 | 20 | #endif | 
 | 21 |  | 
| Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 22 | #ifndef Py_LIMITED_API | 
| Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 23 | typedef struct { | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 24 |     PyObject_VAR_HEAD | 
| Neal Norwitz | 4ecd8cd | 2004-08-01 22:45:27 +0000 | [diff] [blame] | 25 |     /* Vector of pointers to list elements.  list[0] is ob_item[0], etc. */ | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 26 |     PyObject **ob_item; | 
| Tim Peters | a995a2d | 2004-07-29 03:29:15 +0000 | [diff] [blame] | 27 |  | 
 | 28 |     /* ob_item contains space for 'allocated' elements.  The number | 
 | 29 |      * currently in use is ob_size. | 
 | 30 |      * Invariants: | 
 | 31 |      *     0 <= ob_size <= allocated | 
 | 32 |      *     len(list) == ob_size | 
 | 33 |      *     ob_item == NULL implies ob_size == allocated == 0 | 
| Armin Rigo | 93677f0 | 2004-07-29 12:40:23 +0000 | [diff] [blame] | 34 |      * list.sort() temporarily sets allocated to -1 to detect mutations. | 
| Armin Rigo | 89a3946 | 2004-10-28 16:32:00 +0000 | [diff] [blame] | 35 |      * | 
 | 36 |      * Items must normally not be NULL, except during construction when | 
 | 37 |      * the list is not yet visible outside the function that builds it. | 
| Tim Peters | a995a2d | 2004-07-29 03:29:15 +0000 | [diff] [blame] | 38 |      */ | 
| Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 39 |     Py_ssize_t allocated; | 
| Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 40 | } PyListObject; | 
| Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 41 | #endif | 
| Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 42 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 43 | PyAPI_DATA(PyTypeObject) PyList_Type; | 
| Christian Heimes | a22e8bd | 2007-11-29 22:35:39 +0000 | [diff] [blame] | 44 | PyAPI_DATA(PyTypeObject) PyListIter_Type; | 
 | 45 | PyAPI_DATA(PyTypeObject) PyListRevIter_Type; | 
 | 46 | PyAPI_DATA(PyTypeObject) PySortWrapper_Type; | 
| Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 47 |  | 
| Thomas Wouters | 27d517b | 2007-02-25 20:39:11 +0000 | [diff] [blame] | 48 | #define PyList_Check(op) \ | 
| Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 49 | 		PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS) | 
 | 50 | #define PyList_CheckExact(op) (Py_TYPE(op) == &PyList_Type) | 
| Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 51 |  | 
| Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 52 | PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size); | 
 | 53 | PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *); | 
 | 54 | PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t); | 
 | 55 | PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *); | 
 | 56 | PyAPI_FUNC(int) PyList_Insert(PyObject *, Py_ssize_t, PyObject *); | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 57 | PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *); | 
| Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 58 | PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); | 
 | 59 | PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *); | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 60 | PyAPI_FUNC(int) PyList_Sort(PyObject *); | 
 | 61 | PyAPI_FUNC(int) PyList_Reverse(PyObject *); | 
 | 62 | PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *); | 
| Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 63 | #ifndef Py_LIMITED_API | 
| Raymond Hettinger | 8ca92ae | 2004-03-11 09:13:12 +0000 | [diff] [blame] | 64 | PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *); | 
| Antoine Pitrou | 9a812cb | 2011-11-15 00:00:12 +0100 | [diff] [blame] | 65 |  | 
 | 66 | PyAPI_FUNC(int) PyList_ClearFreeList(void); | 
| Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 67 | #endif | 
| Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 68 |  | 
 | 69 | /* Macro, trading safety for speed */ | 
| Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 70 | #ifndef Py_LIMITED_API | 
| Barry Warsaw | 1f2bd07 | 1997-01-06 22:42:00 +0000 | [diff] [blame] | 71 | #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i]) | 
| Guido van Rossum | a937d14 | 1998-04-24 18:22:02 +0000 | [diff] [blame] | 72 | #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v)) | 
| Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 73 | #define PyList_GET_SIZE(op)    Py_SIZE(op) | 
| Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 74 | #endif | 
| Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 75 |  | 
 | 76 | #ifdef __cplusplus | 
 | 77 | } | 
 | 78 | #endif | 
 | 79 | #endif /* !Py_LISTOBJECT_H */ |