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) (_PyList_CAST(op)->ob_item) 39 40 extern int 41 _PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem); 42 43 static inline int _PyList_AppendTakeRef(PyListObject *self, PyObject *newitem)44_PyList_AppendTakeRef(PyListObject *self, PyObject *newitem) 45 { 46 assert(self != NULL && newitem != NULL); 47 assert(PyList_Check(self)); 48 Py_ssize_t len = PyList_GET_SIZE(self); 49 Py_ssize_t allocated = self->allocated; 50 assert((size_t)len + 1 < PY_SSIZE_T_MAX); 51 if (allocated > len) { 52 PyList_SET_ITEM(self, len, newitem); 53 Py_SET_SIZE(self, len + 1); 54 return 0; 55 } 56 return _PyList_AppendTakeRefListResize(self, newitem); 57 } 58 59 #ifdef __cplusplus 60 } 61 #endif 62 #endif /* !Py_INTERNAL_LIST_H */ 63