Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1 | /* An arena-like memory interface for the compiler. |
| 2 | */ |
| 3 | |
| 4 | #ifndef Py_PYARENA_H |
| 5 | #define Py_PYARENA_H |
| 6 | |
| 7 | #ifdef __cplusplus |
| 8 | extern "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 Peters | cb9426b | 2006-03-02 21:04:08 +0000 | [diff] [blame^] | 15 | 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 Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 25 | |
| 26 | PyArena_New() returns an arena pointer. On error, it |
| 27 | returns a negative number and sets an exception. |
Tim Peters | 5f4390f | 2006-03-02 20:48:25 +0000 | [diff] [blame] | 28 | 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 Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 34 | */ |
| 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 Hylton | 77f1bb2 | 2006-02-28 17:53:04 +0000 | [diff] [blame] | 40 | /* 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 Peters | 8cfaa0e | 2006-03-02 20:37:32 +0000 | [diff] [blame] | 43 | */ |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 44 | PyAPI_FUNC(int) PyArena_AddPyObject(PyArena *, PyObject *); |
| 45 | |
| 46 | #ifdef __cplusplus |
| 47 | } |
| 48 | #endif |
| 49 | |
| 50 | #endif /* !Py_PYARENA_H */ |