jpayne@69: jpayne@69: /* List object interface */ jpayne@69: jpayne@69: /* jpayne@69: Another generally useful object type is a list of object pointers. jpayne@69: This is a mutable type: the list items can be changed, and items can be jpayne@69: added or removed. Out-of-range indices or non-list objects are ignored. jpayne@69: jpayne@69: *** WARNING *** PyList_SetItem does not increment the new item's reference jpayne@69: count, but does decrement the reference count of the item it replaces, jpayne@69: if not nil. It does *decrement* the reference count if it is *not* jpayne@69: inserted in the list. Similarly, PyList_GetItem does not increment the jpayne@69: returned item's reference count. jpayne@69: */ jpayne@69: jpayne@69: #ifndef Py_LISTOBJECT_H jpayne@69: #define Py_LISTOBJECT_H jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: #ifndef Py_LIMITED_API jpayne@69: typedef struct { jpayne@69: PyObject_VAR_HEAD jpayne@69: /* Vector of pointers to list elements. list[0] is ob_item[0], etc. */ jpayne@69: PyObject **ob_item; jpayne@69: jpayne@69: /* ob_item contains space for 'allocated' elements. The number jpayne@69: * currently in use is ob_size. jpayne@69: * Invariants: jpayne@69: * 0 <= ob_size <= allocated jpayne@69: * len(list) == ob_size jpayne@69: * ob_item == NULL implies ob_size == allocated == 0 jpayne@69: * list.sort() temporarily sets allocated to -1 to detect mutations. jpayne@69: * jpayne@69: * Items must normally not be NULL, except during construction when jpayne@69: * the list is not yet visible outside the function that builds it. jpayne@69: */ jpayne@69: Py_ssize_t allocated; jpayne@69: } PyListObject; jpayne@69: #endif jpayne@69: jpayne@69: PyAPI_DATA(PyTypeObject) PyList_Type; jpayne@69: PyAPI_DATA(PyTypeObject) PyListIter_Type; jpayne@69: PyAPI_DATA(PyTypeObject) PyListRevIter_Type; jpayne@69: PyAPI_DATA(PyTypeObject) PySortWrapper_Type; jpayne@69: jpayne@69: #define PyList_Check(op) \ jpayne@69: PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS) jpayne@69: #define PyList_CheckExact(op) (Py_TYPE(op) == &PyList_Type) jpayne@69: jpayne@69: PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size); jpayne@69: PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *); jpayne@69: PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t); jpayne@69: PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *); jpayne@69: PyAPI_FUNC(int) PyList_Insert(PyObject *, Py_ssize_t, PyObject *); jpayne@69: PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *); jpayne@69: PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); jpayne@69: PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *); jpayne@69: PyAPI_FUNC(int) PyList_Sort(PyObject *); jpayne@69: PyAPI_FUNC(int) PyList_Reverse(PyObject *); jpayne@69: PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *); jpayne@69: #ifndef Py_LIMITED_API jpayne@69: PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *); jpayne@69: jpayne@69: PyAPI_FUNC(int) PyList_ClearFreeList(void); jpayne@69: PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out); jpayne@69: #endif jpayne@69: jpayne@69: /* Macro, trading safety for speed */ jpayne@69: #ifndef Py_LIMITED_API jpayne@69: #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i]) jpayne@69: #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v)) jpayne@69: #define PyList_GET_SIZE(op) (assert(PyList_Check(op)),Py_SIZE(op)) jpayne@69: #define _PyList_ITEMS(op) (((PyListObject *)(op))->ob_item) jpayne@69: #endif jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } jpayne@69: #endif jpayne@69: #endif /* !Py_LISTOBJECT_H */