Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-19 09:50:41

0001 #ifndef Py_CPYTHON_LISTOBJECT_H
0002 #  error "this header file must not be included directly"
0003 #endif
0004 
0005 typedef struct {
0006     PyObject_VAR_HEAD
0007     /* Vector of pointers to list elements.  list[0] is ob_item[0], etc. */
0008     PyObject **ob_item;
0009 
0010     /* ob_item contains space for 'allocated' elements.  The number
0011      * currently in use is ob_size.
0012      * Invariants:
0013      *     0 <= ob_size <= allocated
0014      *     len(list) == ob_size
0015      *     ob_item == NULL implies ob_size == allocated == 0
0016      * list.sort() temporarily sets allocated to -1 to detect mutations.
0017      *
0018      * Items must normally not be NULL, except during construction when
0019      * the list is not yet visible outside the function that builds it.
0020      */
0021     Py_ssize_t allocated;
0022 } PyListObject;
0023 
0024 /* Cast argument to PyListObject* type. */
0025 #define _PyList_CAST(op) \
0026     (assert(PyList_Check(op)), _Py_CAST(PyListObject*, (op)))
0027 
0028 // Macros and static inline functions, trading safety for speed
0029 
0030 static inline Py_ssize_t PyList_GET_SIZE(PyObject *op) {
0031     PyListObject *list = _PyList_CAST(op);
0032 #ifdef Py_GIL_DISABLED
0033     return _Py_atomic_load_ssize_relaxed(&(_PyVarObject_CAST(list)->ob_size));
0034 #else
0035     return Py_SIZE(list);
0036 #endif
0037 }
0038 #define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))
0039 
0040 #define PyList_GET_ITEM(op, index) (_PyList_CAST(op)->ob_item[(index)])
0041 
0042 static inline void
0043 PyList_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
0044     PyListObject *list = _PyList_CAST(op);
0045     assert(0 <= index);
0046     assert(index < list->allocated);
0047     list->ob_item[index] = value;
0048 }
0049 #define PyList_SET_ITEM(op, index, value) \
0050     PyList_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
0051 
0052 PyAPI_FUNC(int) PyList_Extend(PyObject *self, PyObject *iterable);
0053 PyAPI_FUNC(int) PyList_Clear(PyObject *self);