mirror of
https://github.com/johndoe6345789/typthon.git
synced 2026-04-25 14:15:29 +00:00
Massive automated renaming of all Py_/PyObject/etc. prefixes to Ty_/TyObject/etc. This includes: - All public API types (TyObject, TyTypeObject, etc.) - All public API functions (Ty_Initialize, Ty_BuildValue, etc.) - All internal API (_Ty_ prefixes) - Reference counting macros (Ty_INCREF, Ty_DECREF, etc.) - Type flags (Ty_TPFLAGS_*) - Debug flags (Ty_DEBUG, Ty_TRACE_REFS, etc.) - All object type APIs (TyList_, TyDict_, TyUnicode_, etc.) This changes over 60,000 occurrences across 1000+ files. Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
67 lines
1.6 KiB
C
67 lines
1.6 KiB
C
// Stack of Python objects
|
|
|
|
#include "Python.h"
|
|
#include "pycore_freelist.h"
|
|
#include "pycore_pystate.h"
|
|
#include "pycore_object_stack.h"
|
|
|
|
extern _PyObjectStackChunk *_PyObjectStackChunk_New(void);
|
|
extern void _PyObjectStackChunk_Free(_PyObjectStackChunk *);
|
|
|
|
_PyObjectStackChunk *
|
|
_PyObjectStackChunk_New(void)
|
|
{
|
|
_PyObjectStackChunk *buf = _Ty_FREELIST_POP_MEM(object_stack_chunks);
|
|
if (buf == NULL) {
|
|
// NOTE: we use TyMem_RawMalloc() here because this is used by the GC
|
|
// during mimalloc heap traversal. In that context, it is not safe to
|
|
// allocate mimalloc memory, such as via TyMem_Malloc().
|
|
buf = TyMem_RawMalloc(sizeof(_PyObjectStackChunk));
|
|
if (buf == NULL) {
|
|
return NULL;
|
|
}
|
|
}
|
|
buf->prev = NULL;
|
|
buf->n = 0;
|
|
return buf;
|
|
}
|
|
|
|
void
|
|
_PyObjectStackChunk_Free(_PyObjectStackChunk *buf)
|
|
{
|
|
assert(buf->n == 0);
|
|
_Ty_FREELIST_FREE(object_stack_chunks, buf, TyMem_RawFree);
|
|
}
|
|
|
|
void
|
|
_PyObjectStack_Clear(_PyObjectStack *queue)
|
|
{
|
|
while (queue->head != NULL) {
|
|
_PyObjectStackChunk *buf = queue->head;
|
|
buf->n = 0;
|
|
queue->head = buf->prev;
|
|
_PyObjectStackChunk_Free(buf);
|
|
}
|
|
}
|
|
|
|
void
|
|
_PyObjectStack_Merge(_PyObjectStack *dst, _PyObjectStack *src)
|
|
{
|
|
if (src->head == NULL) {
|
|
return;
|
|
}
|
|
|
|
if (dst->head != NULL) {
|
|
// First, append dst to the bottom of src
|
|
_PyObjectStackChunk *last = src->head;
|
|
while (last->prev != NULL) {
|
|
last = last->prev;
|
|
}
|
|
last->prev = dst->head;
|
|
}
|
|
|
|
// Now that src has all the chunks, set dst to src
|
|
dst->head = src->head;
|
|
src->head = NULL;
|
|
}
|