]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Document that VG_(newPA) and VG_(allocEltPA) never return NULL.
authorFlorian Krohm <florian@eich-krohm.de>
Sun, 14 Sep 2014 22:44:53 +0000 (22:44 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sun, 14 Sep 2014 22:44:53 +0000 (22:44 +0000)
Remove a few pointless asserts.
Avoid conflict with reserved name 'free'.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14537

coregrind/m_poolalloc.c
include/pub_tool_poolalloc.h

index d3bcb9dbcdd0ceb06e81a8520c8aca018cc2ad2c..544239de06e7158d99bb9595bfd37f662ea1d408 100644 (file)
@@ -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. */
index 59c25d54a26cdeceefc388e44b22675bfbfed5e4..4d2b5c128a109869dbf06ab759b4ec08f3617ffe 100644 (file)
@@ -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. */