#include "Python.h" #include "pycore_pyarena.h" // PyArena /* A simple arena block structure. Measurements with standard library modules suggest the average allocation is about 20 bytes and that most compilers use a single block. */ #define DEFAULT_BLOCK_SIZE … #define ALIGNMENT … block; /* The arena manages two kinds of memory, blocks of raw memory and a list of PyObject* pointers. PyObjects are decrefed when the arena is freed. */ struct _arena { … }; static block * block_new(size_t size) { … } static void block_free(block *b) { … } static void * block_alloc(block *b, size_t size) { … } PyArena * _PyArena_New(void) { … } void _PyArena_Free(PyArena *arena) { … } void * _PyArena_Malloc(PyArena *arena, size_t size) { … } int _PyArena_AddPyObject(PyArena *arena, PyObject *obj) { … }