Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6fd92dc

Browse files
committed
Added words about what PyArena_Malloc() does.
1 parent cb9426b commit 6fd92dc

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

Include/pyarena.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,23 @@ extern "C" {
3535
PyAPI_FUNC(PyArena *) PyArena_New(void);
3636
PyAPI_FUNC(void) PyArena_Free(PyArena *);
3737

38-
PyAPI_FUNC(void *) PyArena_Malloc(PyArena *, size_t);
38+
/* Mostly like malloc(), return the address of a block of memory spanning
39+
* `size` bytes, or return NULL (without setting an exception) if enough
40+
* new memory can't be obtained. Unlike malloc(0), PyArena_Malloc() with
41+
* size=0 does not guarantee to return a unique pointer (the pointer
42+
* returned may equal one or more other pointers obtained from
43+
* PyArena_Malloc()).
44+
* Note that pointers obtained via PyArena_Malloc() must never be passed to
45+
* the system free() or realloc(), or to any of Python's similar memory-
46+
* management functions. PyArena_Malloc()-obtained pointers remain valid
47+
* until PyArena_Free(ar) is called, at which point all pointers obtained
48+
* from the arena `ar` become invalid simultaneously.
49+
*/
50+
PyAPI_FUNC(void *) PyArena_Malloc(PyArena *, size_t size);
3951

40-
/* This routines isn't a proper arena allocation routine. It takes
41-
a PyObject* and records it so that it can be DECREFed when the
42-
arena is freed.
52+
/* This routine isn't a proper arena allocation routine. It takes
53+
* a PyObject* and records it so that it can be DECREFed when the
54+
* arena is freed.
4355
*/
4456
PyAPI_FUNC(int) PyArena_AddPyObject(PyArena *, PyObject *);
4557

Python/pyarena.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ PyArena_Malloc(PyArena *arena, size_t size)
150150
arena->total_blocks++;
151151
arena->total_block_size += arena->a_cur->ab_size;
152152
if (arena->a_cur->ab_size > DEFAULT_BLOCK_SIZE)
153-
arena->total_big_blocks++;
153+
++arena->total_big_blocks;
154154
#endif
155155
}
156156
return p;

0 commit comments

Comments
 (0)