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