Document that VG_(newPA) and VG_(allocEltPA) never return NULL.
Remove a few pointless asserts.
Avoid conflict with reserved name 'free'.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14537 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_poolalloc.c b/coregrind/m_poolalloc.c
index d3bcb9d..544239d 100644
--- a/coregrind/m_poolalloc.c
+++ b/coregrind/m_poolalloc.c
@@ -36,9 +36,9 @@
UWord nrRef; /* nr reference to this pool allocator */
UWord elemSzB; /* element size */
UWord nPerPool; /* # elems per pool */
- void* (*alloc)(const HChar*, SizeT); /* pool allocator */
- const HChar* cc; /* pool allocator's cc */
- void (*free)(void*); /* pool allocator's free-er */
+ void* (*alloc_fn)(const HChar*, SizeT); /* pool allocator */
+ const HChar* cc; /* pool allocator's cost centre */
+ void (*free_fn)(void*); /* pool allocator's free-er */
/* XArray of void* (pointers to pools). The pools themselves.
Each element is a pointer to a block of size (elemSzB *
nPerPool) bytes. */
@@ -50,7 +50,7 @@
PoolAlloc* VG_(newPA) ( UWord elemSzB,
UWord nPerPool,
- void* (*alloc)(const HChar*, SizeT),
+ void* (*alloc_fn)(const HChar*, SizeT),
const HChar* cc,
void (*free_fn)(void*) )
{
@@ -58,20 +58,19 @@
vg_assert(0 == (elemSzB % sizeof(UWord)));
vg_assert(elemSzB >= sizeof(UWord));
vg_assert(nPerPool >= 100); /* let's say */
- vg_assert(alloc);
+ vg_assert(alloc_fn);
vg_assert(cc);
vg_assert(free_fn);
- pa = alloc(cc, sizeof(*pa));
- vg_assert(pa);
+ pa = alloc_fn(cc, sizeof(*pa));
VG_(memset)(pa, 0, sizeof(*pa));
pa->nrRef = 0;
pa->elemSzB = elemSzB;
pa->nPerPool = nPerPool;
pa->pools = NULL;
- pa->alloc = alloc;
+ pa->alloc_fn = alloc_fn;
pa->cc = cc;
- pa->free = free_fn;
- pa->pools = VG_(newXA)( alloc, cc, free_fn, sizeof(void*) );
+ pa->free_fn = free_fn;
+ pa->pools = VG_(newXA)( alloc_fn, cc, free_fn, sizeof(void*) );
pa->nextFree = NULL;
vg_assert(pa->pools);
return pa;
@@ -82,9 +81,9 @@
Word i;
vg_assert(pa->nrRef == 0);
for (i = 0; i < VG_(sizeXA) (pa->pools); i++)
- pa->free (*(UWord **)VG_(indexXA) ( pa->pools, i ));
+ pa->free_fn (*(UWord **)VG_(indexXA) ( pa->pools, i ));
VG_(deleteXA) (pa->pools);
- pa->free (pa);
+ pa->free_fn (pa);
}
/* The freelist is empty. Allocate a new pool and put all the new
@@ -96,8 +95,7 @@
UWord* pool;
vg_assert(pa);
vg_assert(pa->nextFree == NULL);
- pool = pa->alloc( pa->cc, pa->elemSzB * pa->nPerPool );
- vg_assert(pool);
+ pool = pa->alloc_fn( pa->cc, pa->elemSzB * pa->nPerPool );
/* extend the freelist through the new pool. Place the freelist
pointer in the first word of each element. That's why the
element size must be at least one word. */
diff --git a/include/pub_tool_poolalloc.h b/include/pub_tool_poolalloc.h
index 59c25d5..4d2b5c1 100644
--- a/include/pub_tool_poolalloc.h
+++ b/include/pub_tool_poolalloc.h
@@ -51,8 +51,9 @@
typedef struct _PoolAlloc PoolAlloc;
/* Create new PoolAlloc, using given allocation and free function, and
- for elements of the specified size. Alloc fn must not fail (that
- is, if it returns it must have succeeded.) */
+ for elements of the specified size. alloc_fn must not return NULL (that
+ is, if it returns it must have succeeded.)
+ This function never returns NULL. */
extern PoolAlloc* VG_(newPA) ( UWord elemSzB,
UWord nPerPool,
void* (*alloc)(const HChar*, SizeT),
@@ -63,7 +64,7 @@
/* Free all memory associated with a PoolAlloc. */
extern void VG_(deletePA) ( PoolAlloc* pa);
-/* Allocates an element from pa. */
+/* Allocates an element from pa. The function never returns NULL. */
extern void* VG_(allocEltPA) ( PoolAlloc* pa);
/* Free element of pa. */