Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | #ifndef Py_LISTOBJECT_H |
2 | #define Py_LISTOBJECT_H | |
3 | #ifdef __cplusplus | |
4 | extern "C" { | |
5 | #endif | |
6 | ||
7 | typedef struct { | |
8 | PyObject_VAR_HEAD | |
9 | /* Vector of pointers to list elements. list[0] is ob_item[0], etc. */ | |
10 | PyObject **ob_item; | |
11 | ||
12 | /* ob_item contains space for 'allocated' elements. The number | |
13 | * currently in use is ob_size. | |
14 | * Invariants: | |
15 | * 0 <= ob_size <= allocated | |
16 | * len(list) == ob_size | |
17 | * ob_item == NULL implies ob_size == allocated == 0 | |
18 | * list.sort() temporarily sets allocated to -1 to detect mutations. | |
19 | * | |
20 | * Items must normally not be NULL, except during construction when | |
21 | * the list is not yet visible outside the function that builds it. | |
22 | */ | |
23 | int allocated; | |
24 | } PyListObject; | |
25 | ||
26 | PyAPI_DATA(PyTypeObject) PyList_Type; | |
27 | ||
28 | #define PyList_Check(op) PyObject_TypeCheck(op, &PyList_Type) | |
29 | #define PyList_CheckExact(op) ((op)->ob_type == &PyList_Type) | |
30 | ||
31 | PyAPI_FUNC(PyObject *) PyList_New(int size); | |
32 | PyAPI_FUNC(int) PyList_Size(PyObject *); | |
33 | PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, int); | |
34 | PyAPI_FUNC(int) PyList_SetItem(PyObject *, int, PyObject *); | |
35 | PyAPI_FUNC(int) PyList_Insert(PyObject *, int, PyObject *); | |
36 | PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *); | |
37 | PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, int, int); | |
38 | PyAPI_FUNC(int) PyList_SetSlice(PyObject *, int, int, PyObject *); | |
39 | PyAPI_FUNC(int) PyList_Sort(PyObject *); | |
40 | PyAPI_FUNC(int) PyList_Reverse(PyObject *); | |
41 | PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *); | |
42 | PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *); | |
43 | ||
44 | /* Macro, trading safety for speed */ | |
45 | #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i]) | |
46 | #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v)) | |
47 | #define PyList_GET_SIZE(op) (((PyListObject *)(op))->ob_size) | |
48 | ||
49 | #ifdef __cplusplus | |
50 | } | |
51 | #endif | |
52 | #endif /* !Py_LISTOBJECT_H */ |