Back to home page

EIC code displayed by LXR

 
 

    


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

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 "pycore_freelist.h"  // _PyFreeListState
0012 
0013 PyAPI_FUNC(PyObject*) _PyList_Extend(PyListObject *, PyObject *);
0014 extern void _PyList_DebugMallocStats(FILE *out);
0015 
0016 #define _PyList_ITEMS(op) _Py_RVALUE(_PyList_CAST(op)->ob_item)
0017 
0018 PyAPI_FUNC(int)
0019 _PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem);
0020 
0021 // In free-threaded build: self should be locked by the caller, if it should be thread-safe.
0022 static inline int
0023 _PyList_AppendTakeRef(PyListObject *self, PyObject *newitem)
0024 {
0025     assert(self != NULL && newitem != NULL);
0026     assert(PyList_Check(self));
0027     Py_ssize_t len = Py_SIZE(self);
0028     Py_ssize_t allocated = self->allocated;
0029     assert((size_t)len + 1 < PY_SSIZE_T_MAX);
0030     if (allocated > len) {
0031 #ifdef Py_GIL_DISABLED
0032         _Py_atomic_store_ptr_release(&self->ob_item[len], newitem);
0033 #else
0034         PyList_SET_ITEM(self, len, newitem);
0035 #endif
0036         Py_SET_SIZE(self, len + 1);
0037         return 0;
0038     }
0039     return _PyList_AppendTakeRefListResize(self, newitem);
0040 }
0041 
0042 // Repeat the bytes of a buffer in place
0043 static inline void
0044 _Py_memory_repeat(char* dest, Py_ssize_t len_dest, Py_ssize_t len_src)
0045 {
0046     assert(len_src > 0);
0047     Py_ssize_t copied = len_src;
0048     while (copied < len_dest) {
0049         Py_ssize_t bytes_to_copy = Py_MIN(copied, len_dest - copied);
0050         memcpy(dest + copied, dest, bytes_to_copy);
0051         copied += bytes_to_copy;
0052     }
0053 }
0054 
0055 typedef struct {
0056     PyObject_HEAD
0057     Py_ssize_t it_index;
0058     PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
0059 } _PyListIterObject;
0060 
0061 PyAPI_FUNC(PyObject *)_PyList_FromArraySteal(PyObject *const *src, Py_ssize_t n);
0062 
0063 #ifdef __cplusplus
0064 }
0065 #endif
0066 #endif   /* !Py_INTERNAL_LIST_H */