From: Florian Krohm Date: Sun, 14 Sep 2014 22:44:53 +0000 (+0000) Subject: Document that VG_(newPA) and VG_(allocEltPA) never return NULL. X-Git-Tag: svn/VALGRIND_3_11_0~995 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e6ce59bc537429905a325a22c66483b3be694f9;p=thirdparty%2Fvalgrind.git 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 --- diff --git a/coregrind/m_poolalloc.c b/coregrind/m_poolalloc.c index d3bcb9dbcd..544239de06 100644 --- a/coregrind/m_poolalloc.c +++ b/coregrind/m_poolalloc.c @@ -36,9 +36,9 @@ struct _PoolAlloc { 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 @@ struct _PoolAlloc { 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 @@ PoolAlloc* VG_(newPA) ( UWord elemSzB, 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 @@ void VG_(deletePA) ( PoolAlloc* pa) 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 @@ static void pal_add_new_pool ( PoolAlloc* pa ) 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 59c25d54a2..4d2b5c128a 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 @@ extern PoolAlloc* VG_(newPA) ( UWord elemSzB, /* 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. */