codekingpro/portable-devtools
114k
1#ifndef Py_INTERNAL_LIST_H2#define Py_INTERNAL_LIST_H3#ifdef __cplusplus4extern "C" {5#endif6 7#ifndef Py_BUILD_CORE8# error "this header requires Py_BUILD_CORE define"9#endif10 11#ifdef Py_GIL_DISABLED12#include "pycore_stackref.h"13#endif14 15PyAPI_FUNC(PyObject*) _PyList_Extend(PyListObject *, PyObject *);16PyAPI_FUNC(PyObject) *_PyList_SliceSubscript(PyObject*, PyObject*);17extern void _PyList_DebugMallocStats(FILE *out);18// _PyList_GetItemRef should be used only when the object is known as a list19// because it doesn't raise TypeError when the object is not a list, whereas PyList_GetItemRef does.20extern PyObject* _PyList_GetItemRef(PyListObject *, Py_ssize_t i);21 22 23#ifdef Py_GIL_DISABLED24// Returns -1 in case of races with other threads.25extern int _PyList_GetItemRefNoLock(PyListObject *, Py_ssize_t, _PyStackRef *);26#endif27 28#define _PyList_ITEMS(op) _Py_RVALUE(_PyList_CAST(op)->ob_item)29 30PyAPI_FUNC(int)31_PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem);32 33// In free-threaded build: self should be locked by the caller, if it should be thread-safe.34static inline int35_PyList_AppendTakeRef(PyListObject *self, PyObject *newitem)36{37 assert(self != NULL && newitem != NULL);38 assert(PyList_Check(self));39 Py_ssize_t len = Py_SIZE(self);40 Py_ssize_t allocated = self->allocated;41 assert((size_t)len + 1 < PY_SSIZE_T_MAX);42 if (allocated > len) {43#ifdef Py_GIL_DISABLED44 _Py_atomic_store_ptr_release(&self->ob_item[len], newitem);45#else46 PyList_SET_ITEM(self, len, newitem);47#endif48 Py_SET_SIZE(self, len + 1);49 return 0;50 }51 return _PyList_AppendTakeRefListResize(self, newitem);52}53 54// Repeat the bytes of a buffer in place55static inline void56_Py_memory_repeat(char* dest, Py_ssize_t len_dest, Py_ssize_t len_src)57{58 assert(len_src > 0);59 Py_ssize_t copied = len_src;60 while (copied < len_dest) {61 Py_ssize_t bytes_to_copy = Py_MIN(copied, len_dest - copied);62 memcpy(dest + copied, dest, (size_t)bytes_to_copy);63 copied += bytes_to_copy;64 }65}66 67typedef struct {68 PyObject_HEAD69 Py_ssize_t it_index;70 PyListObject *it_seq; /* Set to NULL when iterator is exhausted */71} _PyListIterObject;72 73union _PyStackRef;74 75PyAPI_FUNC(PyObject *)_PyList_FromStackRefStealOnSuccess(const union _PyStackRef *src, Py_ssize_t n);76PyAPI_FUNC(PyObject *)_PyList_AsTupleAndClear(PyListObject *v);77 78#ifdef __cplusplus79}80#endif81#endif /* !Py_INTERNAL_LIST_H */82 