PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/Include/listobject.h

http://unladen-swallow.googlecode.com/
C++ Header | 69 lines | 33 code | 10 blank | 26 comment | 1 complexity | 81b22426a677489be9875bef58e51c82 MD5 | raw file
 1
 2/* List object interface */
 3
 4/*
 5Another generally useful object type is an list of object pointers.
 6This is a mutable type: the list items can be changed, and items can be
 7added or removed.  Out-of-range indices or non-list objects are ignored.
 8
 9*** WARNING *** PyList_SetItem does not increment the new item's reference
10count, but does decrement the reference count of the item it replaces,
11if not nil.  It does *decrement* the reference count if it is *not*
12inserted in the list.  Similarly, PyList_GetItem does not increment the
13returned item's reference count.
14*/
15
16#ifndef Py_LISTOBJECT_H
17#define Py_LISTOBJECT_H
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22/* PyListObject; keep in sync with Util/PyTypeBuilder.h. */
23typedef struct PyListObject {
24    PyObject_VAR_HEAD
25    /* Vector of pointers to list elements.  list[0] is ob_item[0], etc. */
26    PyObject **ob_item;
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
34     * list.sort() temporarily sets allocated to -1 to detect mutations.
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.
38     */
39    Py_ssize_t allocated;
40} PyListObject;
41
42PyAPI_DATA(PyTypeObject) PyList_Type;
43
44#define PyList_Check(op) \
45		PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
46#define PyList_CheckExact(op) (Py_TYPE(op) == &PyList_Type)
47
48PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);
49PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *);
50PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t);
51PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *);
52PyAPI_FUNC(int) PyList_Insert(PyObject *, Py_ssize_t, PyObject *);
53PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *);
54PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
55PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
56PyAPI_FUNC(int) PyList_Sort(PyObject *);
57PyAPI_FUNC(int) PyList_Reverse(PyObject *);
58PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *);
59PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *);
60
61/* Macro, trading safety for speed */
62#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
63#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
64#define PyList_GET_SIZE(op)    Py_SIZE(op)
65
66#ifdef __cplusplus
67}
68#endif
69#endif /* !Py_LISTOBJECT_H */