Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
pycore_pyarena.h69 linesDownload Raw Back to internal
1// An arena-like memory interface for the compiler.2 3#ifndef Py_INTERNAL_PYARENA_H4#define Py_INTERNAL_PYARENA_H5#ifdef __cplusplus6extern "C" {7#endif8 9#ifndef Py_BUILD_CORE10#  error "this header requires Py_BUILD_CORE define"11#endif12 13typedef struct _arena PyArena;14 15// _PyArena_New() and _PyArena_Free() create a new arena and free it,16// respectively.  Once an arena has been created, it can be used17// to allocate memory via _PyArena_Malloc().  Pointers to PyObject can18// also be registered with the arena via _PyArena_AddPyObject(), and the19// arena will ensure that the PyObjects stay alive at least until20// _PyArena_Free() is called.  When an arena is freed, all the memory it21// allocated is freed, the arena releases internal references to registered22// PyObject*, and none of its pointers are valid.23// XXX (tim) What does "none of its pointers are valid" mean?  Does it24// XXX mean that pointers previously obtained via _PyArena_Malloc() are25// XXX no longer valid?  (That's clearly true, but not sure that's what26// XXX the text is trying to say.)27//28// _PyArena_New() returns an arena pointer.  On error, it29// returns a negative number and sets an exception.30// XXX (tim):  Not true.  On error, _PyArena_New() actually returns NULL,31// XXX and looks like it may or may not set an exception (e.g., if the32// XXX internal PyList_New(0) returns NULL, _PyArena_New() passes that on33// XXX and an exception is set; OTOH, if the internal34// XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but35// XXX an exception is not set in that case).36//37// Export for test_peg_generator38PyAPI_FUNC(PyArena*) _PyArena_New(void);39 40// Export for test_peg_generator41PyAPI_FUNC(void) _PyArena_Free(PyArena *);42 43// Mostly like malloc(), return the address of a block of memory spanning44// `size` bytes, or return NULL (without setting an exception) if enough45// new memory can't be obtained.  Unlike malloc(0), _PyArena_Malloc() with46// size=0 does not guarantee to return a unique pointer (the pointer47// returned may equal one or more other pointers obtained from48// _PyArena_Malloc()).49// Note that pointers obtained via _PyArena_Malloc() must never be passed to50// the system free() or realloc(), or to any of Python's similar memory-51// management functions.  _PyArena_Malloc()-obtained pointers remain valid52// until _PyArena_Free(ar) is called, at which point all pointers obtained53// from the arena `ar` become invalid simultaneously.54//55// Export for test_peg_generator56PyAPI_FUNC(void*) _PyArena_Malloc(PyArena *, size_t size);57 58// This routine isn't a proper arena allocation routine.  It takes59// a PyObject* and records it so that it can be DECREFed when the60// arena is freed.61//62// Export for test_peg_generator63PyAPI_FUNC(int) _PyArena_AddPyObject(PyArena *, PyObject *);64 65#ifdef __cplusplus66}67#endif68#endif /* !Py_INTERNAL_PYARENA_H */69 
codekingpro/portable-devtools · Team Ai