blob: f5e9eb4b2c9f7609693ae9d9982089f5f5ca32a6 [file] [log] [blame]
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001/* An arena-like memory interface for the compiler.
2 */
3
4#ifndef Py_PYARENA_H
5#define Py_PYARENA_H
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11 typedef struct _arena PyArena;
12
13 /* PyArena_New() and PyArena_Free() create a new arena and free it,
14 respectively. Once an arena has been created, it can be used
Tim Peterscb9426b2006-03-02 21:04:08 +000015 to allocate memory via PyArena_Malloc(). Pointers to PyObject can
16 also be registered with the arena via PyArena_AddPyObject(), and the
17 arena will ensure that the PyObjects stay alive at least until
18 PyArena_Free() is called. When an arena is freed, all the memory it
19 allocated is freed, the arena releases internal references to registered
20 PyObject*, and none of its pointers are valid.
21 XXX (tim) What does "none of its pointers are valid" mean? Does it
22 XXX mean that pointers previously obtained via PyArena_Malloc() are
23 XXX no longer valid? (That's clearly true, but not sure that's what
24 XXX the text is trying to say.)
Neal Norwitzadb69fc2005-12-17 20:54:49 +000025
26 PyArena_New() returns an arena pointer. On error, it
27 returns a negative number and sets an exception.
Tim Peters5f4390f2006-03-02 20:48:25 +000028 XXX (tim): Not true. On error, PyArena_New() actually returns NULL,
29 XXX and looks like it may or may not set an exception (e.g., if the
30 XXX internal PyList_New(0) returns NULL, PyArena_New() passes that on
31 XXX and an exception is set; OTOH, if the internal
32 XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but
33 XXX an exception is not set in that case).
Neal Norwitzadb69fc2005-12-17 20:54:49 +000034 */
35 PyAPI_FUNC(PyArena *) PyArena_New(void);
36 PyAPI_FUNC(void) PyArena_Free(PyArena *);
37
38 PyAPI_FUNC(void *) PyArena_Malloc(PyArena *, size_t);
39
Jeremy Hylton77f1bb22006-02-28 17:53:04 +000040 /* This routines isn't a proper arena allocation routine. It takes
41 a PyObject* and records it so that it can be DECREFed when the
42 arena is freed.
Tim Peters8cfaa0e2006-03-02 20:37:32 +000043 */
Neal Norwitzadb69fc2005-12-17 20:54:49 +000044 PyAPI_FUNC(int) PyArena_AddPyObject(PyArena *, PyObject *);
45
46#ifdef __cplusplus
47}
48#endif
49
50#endif /* !Py_PYARENA_H */