Branch data Line data Source code
1 : : #ifndef Py_INTERNAL_LIST_H 2 : : #define Py_INTERNAL_LIST_H 3 : : #ifdef __cplusplus 4 : : extern "C" { 5 : : #endif 6 : : 7 : : #ifndef Py_BUILD_CORE 8 : : # error "this header requires Py_BUILD_CORE define" 9 : : #endif 10 : : 11 : : #include "listobject.h" // _PyList_CAST() 12 : : 13 : : 14 : : /* runtime lifecycle */ 15 : : 16 : : extern void _PyList_Fini(PyInterpreterState *); 17 : : 18 : : 19 : : /* other API */ 20 : : 21 : : #ifndef WITH_FREELISTS 22 : : // without freelists 23 : : # define PyList_MAXFREELIST 0 24 : : #endif 25 : : 26 : : /* Empty list reuse scheme to save calls to malloc and free */ 27 : : #ifndef PyList_MAXFREELIST 28 : : # define PyList_MAXFREELIST 80 29 : : #endif 30 : : 31 : : struct _Py_list_state { 32 : : #if PyList_MAXFREELIST > 0 33 : : PyListObject *free_list[PyList_MAXFREELIST]; 34 : : int numfree; 35 : : #endif 36 : : }; 37 : : 38 : : #define _PyList_ITEMS(op) _Py_RVALUE(_PyList_CAST(op)->ob_item) 39 : : 40 : : extern int 41 : : _PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem); 42 : : 43 : : static inline int 44 : 4414131 : _PyList_AppendTakeRef(PyListObject *self, PyObject *newitem) 45 : : { 46 : : assert(self != NULL && newitem != NULL); 47 : : assert(PyList_Check(self)); 48 : 4414131 : Py_ssize_t len = PyList_GET_SIZE(self); 49 : 4414131 : Py_ssize_t allocated = self->allocated; 50 : : assert((size_t)len + 1 < PY_SSIZE_T_MAX); 51 [ + + ]: 4414131 : if (allocated > len) { 52 : 4175879 : PyList_SET_ITEM(self, len, newitem); 53 : 4175879 : Py_SET_SIZE(self, len + 1); 54 : 4175879 : return 0; 55 : : } 56 : 238252 : return _PyList_AppendTakeRefListResize(self, newitem); 57 : : } 58 : : 59 : : // Repeat the bytes of a buffer in place 60 : : static inline void 61 : 1003 : _Py_memory_repeat(char* dest, Py_ssize_t len_dest, Py_ssize_t len_src) 62 : : { 63 : : assert(len_src > 0); 64 : 1003 : Py_ssize_t copied = len_src; 65 [ + + ]: 5010 : while (copied < len_dest) { 66 : 4007 : Py_ssize_t bytes_to_copy = Py_MIN(copied, len_dest - copied); 67 : 4007 : memcpy(dest + copied, dest, bytes_to_copy); 68 : 4007 : copied += bytes_to_copy; 69 : : } 70 : 1003 : } 71 : : 72 : : typedef struct { 73 : : PyObject_HEAD 74 : : Py_ssize_t it_index; 75 : : PyListObject *it_seq; /* Set to NULL when iterator is exhausted */ 76 : : } _PyListIterObject; 77 : : 78 : : extern PyObject *_PyList_FromArraySteal(PyObject *const *src, Py_ssize_t n); 79 : : 80 : : #ifdef __cplusplus 81 : : } 82 : : #endif 83 : : #endif /* !Py_INTERNAL_LIST_H */