diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2005-12-17 20:54:49 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2005-12-17 20:54:49 (GMT) |
commit | adb69fcdffdc50ee3e1d33b00cd874020197b445 (patch) | |
tree | 9ea2ddcf5d0625a43739da1d5db7915ef597c8b1 /Include/pyarena.h | |
parent | 23a695891069f619b5b992d877820558bb8dc70f (diff) | |
download | cpython-adb69fcdffdc50ee3e1d33b00cd874020197b445.zip cpython-adb69fcdffdc50ee3e1d33b00cd874020197b445.tar.gz cpython-adb69fcdffdc50ee3e1d33b00cd874020197b445.tar.bz2 |
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
simplifies a lot of error handling code, and fixes many memory leaks.
Diffstat (limited to 'Include/pyarena.h')
-rw-r--r-- | Include/pyarena.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Include/pyarena.h b/Include/pyarena.h new file mode 100644 index 0000000..6f191a1 --- /dev/null +++ b/Include/pyarena.h @@ -0,0 +1,42 @@ +/* An arena-like memory interface for the compiler. + */ + +#ifndef Py_PYARENA_H +#define Py_PYARENA_H + +#ifdef __cplusplus +extern "C" { +#endif + + typedef struct _arena PyArena; + + /* PyArena_New() and PyArena_Free() create a new arena and free it, + respectively. Once an arena has been created, it can be used + to allocate memory. Once it is freed, all the memory it allocated + is freed and none of its pointers are valid. + + PyArena_New() returns an arena pointer. On error, it + returns a negative number and sets an exception. + */ + PyAPI_FUNC(PyArena *) PyArena_New(void); + PyAPI_FUNC(void) PyArena_Free(PyArena *); + + PyAPI_FUNC(void *) PyArena_Malloc(PyArena *, size_t); + + /* The next two routines aren't proper arena allocation routines. + They exist to experiment with the arena API without making wholesale + changes to the implementation. + + The two functions register pointers with the arena id. These + are externally allocated pointers that will be freed when the + arena is freed. One takes a pointer allocated with malloc. The + other takes a PyObject that is DECREFed when the arena is freed. + */ + PyAPI_FUNC(int) PyArena_AddMallocPointer(PyArena *, void *); + PyAPI_FUNC(int) PyArena_AddPyObject(PyArena *, PyObject *); + +#ifdef __cplusplus +} +#endif + +#endif /* !Py_PYARENA_H */ |