]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Tidy up m_wordfm.
authorFlorian Krohm <florian@eich-krohm.de>
Sun, 14 Sep 2014 22:11:44 +0000 (22:11 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sun, 14 Sep 2014 22:11:44 +0000 (22:11 +0000)
First, as the allocator function does not fail, there is no need
to assert its return value.
Second, remove commented out (since r8765) function VG_(isEmptyFM).
Third, remove VG_(getNodeSizeFM) from the API. The details of the
implementation do not need to be exposed.
Fourth, for consistency require that the copy functions for keys and
values in VG_(dopyFM) (which are essentially like allocators) return
non-NULL values for non-NULL arguments if they return.
Fifth, document NULL-ness of return values for VG_(newFM), VG_(dopyFM),
and VG_(newBag). Remove pointless asserts at call sites.
Six, change avl_dopy to assert that the node the function is
supposed to copy is not NULL. It is called that way anyhow. With
that change the function never returns NULL which allows us to
simplify the call sites. Checking the return value is no longer needed.

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

coregrind/m_wordfm.c
helgrind/hg_errors.c
helgrind/hg_main.c
helgrind/libhb_core.c
include/pub_tool_wordfm.h

index f3e517ce60b0777b0bdbdf27e829d89474ed4c77..203824512d492ce67927a70bd0eb7533e75eef6b 100644 (file)
@@ -506,10 +506,10 @@ AvlNode* avl_dopy ( AvlNode* nd,
                     const HChar* cc )
 {
    AvlNode* nyu;
-   if (! nd)
-      return NULL;
+
+   vg_assert(nd != NULL);
+
    nyu = alloc_nofail(cc, sizeof(AvlNode));
-   tl_assert(nyu);
    
    nyu->child[0] = nd->child[0];
    nyu->child[1] = nd->child[1];
@@ -518,8 +518,6 @@ AvlNode* avl_dopy ( AvlNode* nd,
    /* Copy key */
    if (dopyK) {
       nyu->key = dopyK( nd->key );
-      if (nd->key != 0 && nyu->key == 0)
-         return NULL; /* oom in key dcopy */
    } else {
       /* copying assumedly unboxed keys */
       nyu->key = nd->key;
@@ -528,8 +526,6 @@ AvlNode* avl_dopy ( AvlNode* nd,
    /* Copy val */
    if (dopyV) {
       nyu->val = dopyV( nd->val );
-      if (nd->val != 0 && nyu->val == 0)
-         return NULL; /* oom in val dcopy */
    } else {
       /* copying assumedly unboxed vals */
       nyu->val = nd->val;
@@ -539,14 +535,10 @@ AvlNode* avl_dopy ( AvlNode* nd,
    if (nyu->child[0]) {
       nyu->child[0] = avl_dopy( nyu->child[0], dopyK, dopyV, 
                                 alloc_nofail, cc );
-      if (! nyu->child[0])
-         return NULL;
    }
    if (nyu->child[1]) {
       nyu->child[1] = avl_dopy( nyu->child[1], dopyK, dopyV,
                                 alloc_nofail, cc );
-      if (! nyu->child[1])
-         return NULL;
    }
 
    return nyu;
@@ -582,7 +574,6 @@ WordFM* VG_(newFM) ( void* (*alloc_nofail)( const HChar*, SizeT ),
                      Word  (*kCmp)(UWord,UWord) )
 {
    WordFM* fm = alloc_nofail(cc, sizeof(WordFM));
-   tl_assert(fm);
    initFM(fm, alloc_nofail, cc, dealloc, kCmp);
    return fm;
 }
@@ -797,7 +788,7 @@ Bool VG_(nextIterFM) ( WordFM* fm, /*OUT*/UWord* pKey, /*OUT*/UWord* pVal )
    return False;
 }
 
-// clear the I'm iterating flag
+// Finish an FM iteration
 void VG_(doneIterFM) ( WordFM* fm )
 {
 }
@@ -810,7 +801,6 @@ WordFM* VG_(dopyFM) ( WordFM* fm, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) )
    tl_assert(fm->stackTop == 0);
 
    nyu = fm->alloc_nofail( fm->cc, sizeof(WordFM) );
-   tl_assert(nyu);
 
    *nyu = *fm;
 
@@ -828,12 +818,6 @@ WordFM* VG_(dopyFM) ( WordFM* fm, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) )
    return nyu;
 }
 
-// admin: what's the 'common' allocation size (for tree nodes?)
-SizeT VG_(getNodeSizeFM)( void )
-{
-   return sizeof(AvlNode);
-}
-
 //------------------------------------------------------------------//
 //---                         end WordFM                         ---//
 //---                       Implementation                       ---//
index 21ed9c1bc201a6673e1493783fc181d629911663..93ea58d39be62fd8a3adb0068d9fc86db3b19fda 100644 (file)
@@ -76,7 +76,6 @@ static HChar* string_table_strdup ( const HChar* str ) {
    if (!string_table) {
       string_table = VG_(newFM)( HG_(zalloc), "hg.sts.1",
                                  HG_(free), string_table_cmp );
-      tl_assert(string_table);
    }
    if (VG_(lookupFM)( string_table,
                       NULL, (UWord*)&copy, (UWord)str )) {
@@ -164,7 +163,6 @@ static Lock* mk_LockP_from_LockN ( Lock* lkn,
    if (!map_LockN_to_P) {
       map_LockN_to_P = VG_(newFM)( HG_(zalloc), "hg.mLPfLN.1",
                                    HG_(free), lock_unique_cmp );
-      tl_assert(map_LockN_to_P);
    }
    if (!VG_(lookupFM)( map_LockN_to_P, NULL, (UWord*)&lkp, (UWord)lkn)) {
       lkp = HG_(zalloc)( "hg.mLPfLN.2", sizeof(Lock) );
index 9691e0cf5c22f618a8a42cd2f4ca4a2cf31d5483..445395420de3d9314363aa936d0095d169e2bc09 100644 (file)
@@ -600,7 +600,6 @@ static void initialise_data_structures ( Thr* hbthr_root )
    tl_assert(map_locks == NULL);
    map_locks = VG_(newFM)( HG_(zalloc), "hg.ids.2", HG_(free), 
                            NULL/*unboxed Word cmp*/);
-   tl_assert(map_locks != NULL);
 
    tl_assert(univ_lsets == NULL);
    univ_lsets = HG_(newWordSetU)( HG_(zalloc), "hg.ids.4", HG_(free),
@@ -2170,7 +2169,6 @@ static void map_cond_to_CVInfo_INIT ( void ) {
    if (UNLIKELY(map_cond_to_CVInfo == NULL)) {
       map_cond_to_CVInfo = VG_(newFM)( HG_(zalloc),
                                        "hg.mctCI.1", HG_(free), NULL );
-      tl_assert(map_cond_to_CVInfo != NULL);
    }
 }
 
@@ -2653,7 +2651,6 @@ static void map_sem_to_SO_stack_INIT ( void ) {
    if (map_sem_to_SO_stack == NULL) {
       map_sem_to_SO_stack = VG_(newFM)( HG_(zalloc), "hg.mstSs.1",
                                         HG_(free), NULL );
-      tl_assert(map_sem_to_SO_stack != NULL);
    }
 }
 
@@ -2873,7 +2870,6 @@ static void map_barrier_to_Bar_INIT ( void ) {
    if (UNLIKELY(map_barrier_to_Bar == NULL)) {
       map_barrier_to_Bar = VG_(newFM)( HG_(zalloc),
                                        "hg.mbtBI.1", HG_(free), NULL );
-      tl_assert(map_barrier_to_Bar != NULL);
    }
 }
 
@@ -3205,7 +3201,6 @@ static void map_usertag_to_SO_INIT ( void ) {
    if (UNLIKELY(map_usertag_to_SO == NULL)) {
       map_usertag_to_SO = VG_(newFM)( HG_(zalloc),
                                       "hg.mutS.1", HG_(free), NULL );
-      tl_assert(map_usertag_to_SO != NULL);
    }
 }
 
@@ -3385,8 +3380,6 @@ static void laog__init ( void )
 
    laog_exposition = VG_(newFM)( HG_(zalloc), "hg.laog__init.2", HG_(free), 
                                  cmp_LAOGLinkExposition );
-   tl_assert(laog);
-   tl_assert(laog_exposition);
 }
 
 static void laog__show ( const HChar* who ) {
@@ -4744,7 +4737,6 @@ static void map_pthread_t_to_Thread_INIT ( void ) {
    if (UNLIKELY(map_pthread_t_to_Thread == NULL)) {
       map_pthread_t_to_Thread = VG_(newFM)( HG_(zalloc), "hg.mpttT.1", 
                                             HG_(free), NULL );
-      tl_assert(map_pthread_t_to_Thread != NULL);
    }
 }
 
index bd26f28a3b72316bcdb7fb8a1fdc41ee60861e5b..e1a18a7c9ab633167cacd26bd2cc8c85f51b511c 100644 (file)
@@ -1758,7 +1758,6 @@ static void zsm_init ( void(*p_rcinc)(SVal), void(*p_rcdec)(SVal) )
    map_shmem = VG_(newFM)( HG_(zalloc), "libhb.zsm_init.1 (map_shmem)",
                            HG_(free), 
                            NULL/*unboxed UWord cmp*/);
-   tl_assert(map_shmem != NULL);
    shmem__invalidate_scache();
 
    /* a SecMap must contain an integral number of CacheLines */
@@ -2489,7 +2488,6 @@ static void vts_set_init ( void )
    vts_set = VG_(newFM)( HG_(zalloc), "libhb.vts_set_init.1",
                          HG_(free),
                          (Word(*)(UWord,UWord))VTS__cmp_structural );
-   tl_assert(vts_set);
 }
 
 /* Given a VTS, look in vts_set to see if we already have a
index f0fdb58d025b2cf0af60c29ae9b96da409768662..bd7e2214bad2b474ba30dd75831c279c2b28577f 100644 (file)
@@ -77,7 +77,8 @@ typedef  struct _WordFM  WordFM; /* opaque */
    VG_(initIterAtFM), VG_(nextIterFM), VG_(doneIterFM) to iterate over
    sections of the map, or the whole thing.  If kCmp is NULL then the
    ordering used is unsigned word ordering (UWord) on the key
-   values. */
+   values.
+   The function never returns NULL. */
 WordFM* VG_(newFM) ( void* (*alloc_nofail)( const HChar* cc, SizeT ),
                      const HChar* cc,
                      void  (*dealloc)(void*),
@@ -129,11 +130,6 @@ Bool VG_(findBoundsFM)( WordFM* fm,
 // since it involves walking the whole tree.
 UWord VG_(sizeFM) ( WordFM* fm );
 
-// Is fm empty?  This at least is an O(1) operation.
-// Code is present in m_wordfm.c but commented out due to no
-// current usage.  Un-comment (and TEST IT) if required.
-//Bool VG_(isEmptyFM)( WordFM* fm );
-
 // set up FM for iteration
 void VG_(initIterFM) ( WordFM* fm );
 
@@ -148,21 +144,18 @@ void VG_(initIterAtFM) ( WordFM* fm, UWord start_at );
 Bool VG_(nextIterFM) ( WordFM* fm,
                        /*OUT*/UWord* pKey, /*OUT*/UWord* pVal );
 
-// clear the I'm iterating flag
+// Finish an FM iteration
 void VG_(doneIterFM) ( WordFM* fm );
 
 // Deep copy a FM.  If dopyK is NULL, keys are copied verbatim.
 // If non-null, dopyK is applied to each key to generate the
-// version in the new copy.  In that case, if the argument to dopyK
-// is non-NULL but the result is NULL, it is assumed that dopyK
-// could not allocate memory, in which case the copy is abandoned
-// and NULL is returned.  Ditto with dopyV for values.
+// version in the new copy.  dopyK may be called with a NULL argument
+// in which case it should return NULL. For all other argument values
+// dopyK must not return NULL. Ditto with dopyV for values.
+// VG_(dopyFM) never returns NULL.
 WordFM* VG_(dopyFM) ( WordFM* fm,
                       UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) );
 
-// admin: what's the 'common' allocation size (for tree nodes?)
-SizeT VG_(getNodeSizeFM)( void );
-
 //------------------------------------------------------------------//
 //---                         end WordFM                         ---//
 //---                      Public interface                      ---//
@@ -175,7 +168,7 @@ SizeT VG_(getNodeSizeFM)( void );
 
 typedef  struct _WordBag  WordBag; /* opaque */
 
-/* Allocate and initialise a WordBag */
+/* Allocate and initialise a WordBag. Never returns NULL. */
 WordBag* VG_(newBag) ( void* (*alloc_nofail)( const HChar* cc, SizeT ),
                        const HChar* cc,
                        void  (*dealloc)(void*) );