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