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