From: Florian Krohm Date: Mon, 15 Sep 2014 07:21:36 +0000 (+0000) Subject: Document NULL-ness of the return value of the dedup allocation functions. X-Git-Tag: svn/VALGRIND_3_11_0~994 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbc6e90d5bef7d00835106c1e40f6640a1842f7e;p=thirdparty%2Fvalgrind.git Document NULL-ness of the return value of the dedup allocation functions. Avoid conflict with reserved name 'free'. Remove a few pointless asserts. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14538 --- diff --git a/coregrind/m_deduppoolalloc.c b/coregrind/m_deduppoolalloc.c index 05e03b60b9..8a203e88e2 100644 --- a/coregrind/m_deduppoolalloc.c +++ b/coregrind/m_deduppoolalloc.c @@ -42,9 +42,9 @@ struct _DedupPoolAlloc { SizeT poolSzB; /* Minimum size of a pool. */ SizeT fixedSzb; /* If using VG_(allocFixedEltDedupPA), size of elements */ SizeT eltAlign; - 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 deallocation function */ /* XArray of void* (pointers to pools). The pools themselves. Each element is a pointer to a block of size at least PoolSzB bytes. The last block might be smaller due to a call to shrink_block. */ @@ -80,34 +80,33 @@ typedef } ht_node; -extern DedupPoolAlloc* VG_(newDedupPA) ( SizeT poolSzB, - SizeT eltAlign, - void* (*alloc)(const HChar*, SizeT), - const HChar* cc, - void (*free_fn)(void*) ) +DedupPoolAlloc* VG_(newDedupPA) ( SizeT poolSzB, + SizeT eltAlign, + void* (*alloc_fn)(const HChar*, SizeT), + const HChar* cc, + void (*free_fn)(void*) ) { DedupPoolAlloc* ddpa; vg_assert(poolSzB >= eltAlign); vg_assert(poolSzB >= 100); /* let's say */ vg_assert(poolSzB >= 10*eltAlign); /* let's say */ - vg_assert(alloc); + vg_assert(alloc_fn); vg_assert(cc); vg_assert(free_fn); - ddpa = alloc(cc, sizeof(*ddpa)); - vg_assert(ddpa); + ddpa = alloc_fn(cc, sizeof(*ddpa)); VG_(memset)(ddpa, 0, sizeof(*ddpa)); ddpa->poolSzB = poolSzB; ddpa->fixedSzb = 0; ddpa->eltAlign = eltAlign; - ddpa->alloc = alloc; + ddpa->alloc_fn = alloc_fn; ddpa->cc = cc; - ddpa->free = free_fn; - ddpa->pools = VG_(newXA)( alloc, cc, free_fn, sizeof(void*) ); + ddpa->free_fn = free_fn; + ddpa->pools = VG_(newXA)( alloc_fn, cc, free_fn, sizeof(void*) ); ddpa->ht_elements = VG_(HT_construct) (cc); ddpa->ht_node_pa = VG_(newPA) ( sizeof(ht_node), 1000, - alloc, + alloc_fn, cc, free_fn); ddpa->curpool = NULL; @@ -124,9 +123,9 @@ void VG_(deleteDedupPA) ( DedupPoolAlloc* ddpa) // Free data structures used for insertion. VG_(freezeDedupPA) (ddpa, NULL); for (i = 0; i < VG_(sizeXA) (ddpa->pools); i++) - ddpa->free (*(UWord **)VG_(indexXA) ( ddpa->pools, i )); + ddpa->free_fn (*(UWord **)VG_(indexXA) ( ddpa->pools, i )); VG_(deleteXA) (ddpa->pools); - ddpa->free (ddpa); + ddpa->free_fn (ddpa); } static __inline__ @@ -146,13 +145,12 @@ static void ddpa_add_new_pool_or_grow ( DedupPoolAlloc* ddpa ) UChar *curpool_align = ddpa_align(ddpa, ddpa->curpool); SizeT curpool_used = ddpa->curpool_free - curpool_align; SizeT curpool_size = ddpa->curpool_limit - ddpa->curpool + 1; - UChar *newpool = ddpa->alloc (ddpa->cc, 2 * curpool_size); + UChar *newpool = ddpa->alloc_fn (ddpa->cc, 2 * curpool_size); UChar *newpool_free = ddpa_align (ddpa, newpool); UChar *newpool_limit = newpool + 2 * curpool_size - 1; Word reloc_offset = (Addr)newpool_free - (Addr)curpool_align; ht_node *n; - vg_assert (newpool); VG_(memcpy) (newpool_free, curpool_align, curpool_used); /* We have reallocated the (only) pool. We need to relocate the pointers in the hash table nodes. */ @@ -163,7 +161,7 @@ static void ddpa_add_new_pool_or_grow ( DedupPoolAlloc* ddpa ) newpool_free += curpool_used; VG_(dropHeadXA) (ddpa->pools, 1); - ddpa->free (ddpa->curpool); + ddpa->free_fn (ddpa->curpool); ddpa->curpool = newpool; ddpa->curpool_free = newpool_free; ddpa->curpool_limit = newpool_limit; @@ -171,8 +169,7 @@ static void ddpa_add_new_pool_or_grow ( DedupPoolAlloc* ddpa ) } else { /* Allocate a new pool, or allocate the first/only pool for a fixed size ddpa. */ - ddpa->curpool = ddpa->alloc( ddpa->cc, ddpa->poolSzB); - vg_assert(ddpa->curpool); + ddpa->curpool = ddpa->alloc_fn( ddpa->cc, ddpa->poolSzB); ddpa->curpool_limit = ddpa->curpool + ddpa->poolSzB - 1; ddpa->curpool_free = ddpa_align (ddpa, ddpa->curpool); /* add to our collection of pools */ diff --git a/include/pub_tool_deduppoolalloc.h b/include/pub_tool_deduppoolalloc.h index c048b77f1e..2ba7f2063d 100644 --- a/include/pub_tool_deduppoolalloc.h +++ b/include/pub_tool_deduppoolalloc.h @@ -80,23 +80,26 @@ typedef struct _DedupPoolAlloc DedupPoolAlloc; /* Create new DedupPoolAlloc, using given allocation and free function. - Alloc fn must not fail (that is, if it returns it must have succeeded.) + alloc_fn must not return NULL (that is, if it returns it must have + succeeded.) poolSzB is the (minimum) size in bytes of the pool of elements allocated with alloc. eltAlign is the minimum required alignement for the elements allocated - from the DedupPoolAlloc. */ + from the DedupPoolAlloc. + This function never returns NULL. */ extern DedupPoolAlloc* VG_(newDedupPA) ( SizeT poolSzB, SizeT eltAlign, void* (*alloc)(const HChar*, SizeT), const HChar* cc, void (*free_fn)(void*) ); -/* Allocates a new element from ddpa with eltSzB bytes to store elt. */ +/* Allocates a new element from ddpa with eltSzB bytes to store elt. + This function never returns NULL. */ extern void* VG_(allocEltDedupPA) (DedupPoolAlloc *ddpa, SizeT eltSzB, const void *elt); /* Allocates a new (fixed size) element from ddpa. Returns the - unique number identifying this element. */ + unique number identifying this element. This function never returns NULL. */ extern UInt VG_(allocFixedEltDedupPA) (DedupPoolAlloc *ddpa, SizeT eltSzB, const void *elt);