|
||||
File indexing completed on 2025-01-18 10:06:46
0001 /* An arena-like memory interface for the compiler. 0002 */ 0003 0004 #ifndef Py_INTERNAL_PYARENA_H 0005 #define Py_INTERNAL_PYARENA_H 0006 #ifdef __cplusplus 0007 extern "C" { 0008 #endif 0009 0010 #ifndef Py_BUILD_CORE 0011 # error "this header requires Py_BUILD_CORE define" 0012 #endif 0013 0014 typedef struct _arena PyArena; 0015 0016 /* _PyArena_New() and _PyArena_Free() create a new arena and free it, 0017 respectively. Once an arena has been created, it can be used 0018 to allocate memory via _PyArena_Malloc(). Pointers to PyObject can 0019 also be registered with the arena via _PyArena_AddPyObject(), and the 0020 arena will ensure that the PyObjects stay alive at least until 0021 _PyArena_Free() is called. When an arena is freed, all the memory it 0022 allocated is freed, the arena releases internal references to registered 0023 PyObject*, and none of its pointers are valid. 0024 XXX (tim) What does "none of its pointers are valid" mean? Does it 0025 XXX mean that pointers previously obtained via _PyArena_Malloc() are 0026 XXX no longer valid? (That's clearly true, but not sure that's what 0027 XXX the text is trying to say.) 0028 0029 _PyArena_New() returns an arena pointer. On error, it 0030 returns a negative number and sets an exception. 0031 XXX (tim): Not true. On error, _PyArena_New() actually returns NULL, 0032 XXX and looks like it may or may not set an exception (e.g., if the 0033 XXX internal PyList_New(0) returns NULL, _PyArena_New() passes that on 0034 XXX and an exception is set; OTOH, if the internal 0035 XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but 0036 XXX an exception is not set in that case). 0037 */ 0038 PyAPI_FUNC(PyArena*) _PyArena_New(void); 0039 PyAPI_FUNC(void) _PyArena_Free(PyArena *); 0040 0041 /* Mostly like malloc(), return the address of a block of memory spanning 0042 * `size` bytes, or return NULL (without setting an exception) if enough 0043 * new memory can't be obtained. Unlike malloc(0), _PyArena_Malloc() with 0044 * size=0 does not guarantee to return a unique pointer (the pointer 0045 * returned may equal one or more other pointers obtained from 0046 * _PyArena_Malloc()). 0047 * Note that pointers obtained via _PyArena_Malloc() must never be passed to 0048 * the system free() or realloc(), or to any of Python's similar memory- 0049 * management functions. _PyArena_Malloc()-obtained pointers remain valid 0050 * until _PyArena_Free(ar) is called, at which point all pointers obtained 0051 * from the arena `ar` become invalid simultaneously. 0052 */ 0053 PyAPI_FUNC(void*) _PyArena_Malloc(PyArena *, size_t size); 0054 0055 /* This routine isn't a proper arena allocation routine. It takes 0056 * a PyObject* and records it so that it can be DECREFed when the 0057 * arena is freed. 0058 */ 0059 PyAPI_FUNC(int) _PyArena_AddPyObject(PyArena *, PyObject *); 0060 0061 #ifdef __cplusplus 0062 } 0063 #endif 0064 #endif /* !Py_INTERNAL_PYARENA_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |