File indexing completed on 2025-01-18 10:06:45
0001 #ifndef Py_INTERNAL_LIST_H
0002 #define Py_INTERNAL_LIST_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006
0007 #ifndef Py_BUILD_CORE
0008 # error "this header requires Py_BUILD_CORE define"
0009 #endif
0010
0011 #include "listobject.h" // _PyList_CAST()
0012
0013
0014
0015
0016 extern void _PyList_Fini(PyInterpreterState *);
0017
0018
0019
0020
0021 #ifndef WITH_FREELISTS
0022
0023 # define PyList_MAXFREELIST 0
0024 #endif
0025
0026
0027 #ifndef PyList_MAXFREELIST
0028 # define PyList_MAXFREELIST 80
0029 #endif
0030
0031 struct _Py_list_state {
0032 #if PyList_MAXFREELIST > 0
0033 PyListObject *free_list[PyList_MAXFREELIST];
0034 int numfree;
0035 #endif
0036 };
0037
0038 #define _PyList_ITEMS(op) _Py_RVALUE(_PyList_CAST(op)->ob_item)
0039
0040 extern int
0041 _PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem);
0042
0043 static inline int
0044 _PyList_AppendTakeRef(PyListObject *self, PyObject *newitem)
0045 {
0046 assert(self != NULL && newitem != NULL);
0047 assert(PyList_Check(self));
0048 Py_ssize_t len = PyList_GET_SIZE(self);
0049 Py_ssize_t allocated = self->allocated;
0050 assert((size_t)len + 1 < PY_SSIZE_T_MAX);
0051 if (allocated > len) {
0052 PyList_SET_ITEM(self, len, newitem);
0053 Py_SET_SIZE(self, len + 1);
0054 return 0;
0055 }
0056 return _PyList_AppendTakeRefListResize(self, newitem);
0057 }
0058
0059
0060 static inline void
0061 _Py_memory_repeat(char* dest, Py_ssize_t len_dest, Py_ssize_t len_src)
0062 {
0063 assert(len_src > 0);
0064 Py_ssize_t copied = len_src;
0065 while (copied < len_dest) {
0066 Py_ssize_t bytes_to_copy = Py_MIN(copied, len_dest - copied);
0067 memcpy(dest + copied, dest, bytes_to_copy);
0068 copied += bytes_to_copy;
0069 }
0070 }
0071
0072 typedef struct {
0073 PyObject_HEAD
0074 Py_ssize_t it_index;
0075 PyListObject *it_seq;
0076 } _PyListIterObject;
0077
0078 extern PyObject *_PyList_FromArraySteal(PyObject *const *src, Py_ssize_t n);
0079
0080 #ifdef __cplusplus
0081 }
0082 #endif
0083 #endif