annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/python3.8/pyarena.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 /* An arena-like memory interface for the compiler.
jpayne@69 2 */
jpayne@69 3
jpayne@69 4 #ifndef Py_LIMITED_API
jpayne@69 5 #ifndef Py_PYARENA_H
jpayne@69 6 #define Py_PYARENA_H
jpayne@69 7
jpayne@69 8 #ifdef __cplusplus
jpayne@69 9 extern "C" {
jpayne@69 10 #endif
jpayne@69 11
jpayne@69 12 typedef struct _arena PyArena;
jpayne@69 13
jpayne@69 14 /* PyArena_New() and PyArena_Free() create a new arena and free it,
jpayne@69 15 respectively. Once an arena has been created, it can be used
jpayne@69 16 to allocate memory via PyArena_Malloc(). Pointers to PyObject can
jpayne@69 17 also be registered with the arena via PyArena_AddPyObject(), and the
jpayne@69 18 arena will ensure that the PyObjects stay alive at least until
jpayne@69 19 PyArena_Free() is called. When an arena is freed, all the memory it
jpayne@69 20 allocated is freed, the arena releases internal references to registered
jpayne@69 21 PyObject*, and none of its pointers are valid.
jpayne@69 22 XXX (tim) What does "none of its pointers are valid" mean? Does it
jpayne@69 23 XXX mean that pointers previously obtained via PyArena_Malloc() are
jpayne@69 24 XXX no longer valid? (That's clearly true, but not sure that's what
jpayne@69 25 XXX the text is trying to say.)
jpayne@69 26
jpayne@69 27 PyArena_New() returns an arena pointer. On error, it
jpayne@69 28 returns a negative number and sets an exception.
jpayne@69 29 XXX (tim): Not true. On error, PyArena_New() actually returns NULL,
jpayne@69 30 XXX and looks like it may or may not set an exception (e.g., if the
jpayne@69 31 XXX internal PyList_New(0) returns NULL, PyArena_New() passes that on
jpayne@69 32 XXX and an exception is set; OTOH, if the internal
jpayne@69 33 XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but
jpayne@69 34 XXX an exception is not set in that case).
jpayne@69 35 */
jpayne@69 36 PyAPI_FUNC(PyArena *) PyArena_New(void);
jpayne@69 37 PyAPI_FUNC(void) PyArena_Free(PyArena *);
jpayne@69 38
jpayne@69 39 /* Mostly like malloc(), return the address of a block of memory spanning
jpayne@69 40 * `size` bytes, or return NULL (without setting an exception) if enough
jpayne@69 41 * new memory can't be obtained. Unlike malloc(0), PyArena_Malloc() with
jpayne@69 42 * size=0 does not guarantee to return a unique pointer (the pointer
jpayne@69 43 * returned may equal one or more other pointers obtained from
jpayne@69 44 * PyArena_Malloc()).
jpayne@69 45 * Note that pointers obtained via PyArena_Malloc() must never be passed to
jpayne@69 46 * the system free() or realloc(), or to any of Python's similar memory-
jpayne@69 47 * management functions. PyArena_Malloc()-obtained pointers remain valid
jpayne@69 48 * until PyArena_Free(ar) is called, at which point all pointers obtained
jpayne@69 49 * from the arena `ar` become invalid simultaneously.
jpayne@69 50 */
jpayne@69 51 PyAPI_FUNC(void *) PyArena_Malloc(PyArena *, size_t size);
jpayne@69 52
jpayne@69 53 /* This routine isn't a proper arena allocation routine. It takes
jpayne@69 54 * a PyObject* and records it so that it can be DECREFed when the
jpayne@69 55 * arena is freed.
jpayne@69 56 */
jpayne@69 57 PyAPI_FUNC(int) PyArena_AddPyObject(PyArena *, PyObject *);
jpayne@69 58
jpayne@69 59 #ifdef __cplusplus
jpayne@69 60 }
jpayne@69 61 #endif
jpayne@69 62
jpayne@69 63 #endif /* !Py_PYARENA_H */
jpayne@69 64 #endif /* Py_LIMITED_API */