Tidy up m_xarray.c.
VG_(newXA) and VG_(cloneXA) never return NULL. Remove pointless asserts.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14539 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_commandline.c b/coregrind/m_commandline.c
index 85e91b4..9f020fd 100644
--- a/coregrind/m_commandline.c
+++ b/coregrind/m_commandline.c
@@ -164,19 +164,16 @@
 
    tmp_xarray = VG_(newXA)( VG_(malloc), "commandline.sua.1",
                             VG_(free), sizeof(HChar*) );
-   vg_assert(tmp_xarray);
 
    vg_assert( ! VG_(args_for_valgrind) );
    VG_(args_for_valgrind)
       = VG_(newXA)( VG_(malloc), "commandline.sua.2",
                     VG_(free), sizeof(HChar*) );
-   vg_assert( VG_(args_for_valgrind) );
 
    vg_assert( ! VG_(args_for_client) );
    VG_(args_for_client)
       = VG_(newXA)( VG_(malloc), "commandline.sua.3",
                     VG_(free), sizeof(HChar*) );
-   vg_assert( VG_(args_for_client) );
 
    /* Collect up the args-for-V. */
    i = 1; /* skip the exe (stage2) name. */
diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c
index 285f7c9..ab11a5a 100644
--- a/coregrind/m_debuginfo/debuginfo.c
+++ b/coregrind/m_debuginfo/debuginfo.c
@@ -3953,7 +3953,6 @@
    /* we'll put the collected variables in here. */
    gvars = VG_(newXA)( ML_(dinfo_zalloc), "di.debuginfo.dggbfd.1",
                        ML_(dinfo_free), sizeof(GlobalBlock) );
-   tl_assert(gvars);
 
    /* any var info at all? */
    if (!di->varinfo)
diff --git a/coregrind/m_debuginfo/readdwarf.c b/coregrind/m_debuginfo/readdwarf.c
index 9a07696..c8021d3 100644
--- a/coregrind/m_debuginfo/readdwarf.c
+++ b/coregrind/m_debuginfo/readdwarf.c
@@ -2073,7 +2073,6 @@
       if (src && (VG_(sizeXA)(src) > 0) && (!dst)) {
          dst = VG_(newXA)( ML_(dinfo_zalloc), "di.ccCt.1", ML_(dinfo_free),
                            sizeof(CfiExpr) );
-         vg_assert(dst);
          debuginfo->cfsi_exprs = dst;
       }
       conv = copy_convert_CfiExpr_tree
@@ -2152,7 +2151,6 @@
                               "di.ccCt.2",                    \
                               ML_(dinfo_free),                \
                               sizeof(CfiExpr) );              \
-            vg_assert(dst);                                   \
             debuginfo->cfsi_exprs = dst;                      \
          }                                                    \
          conv = copy_convert_CfiExpr_tree                     \
@@ -4125,7 +4123,6 @@
          ctx.exprs    = VG_(newXA)( ML_(dinfo_zalloc), "di.rcid.1",
                                     ML_(dinfo_free), 
                                     sizeof(CfiExpr) );
-         vg_assert(ctx.exprs);
 
 	 /* Run the CIE's instructions.  Ugly hack: if
             --debug-dump=frames is in effect, suppress output for
diff --git a/coregrind/m_debuginfo/readdwarf3.c b/coregrind/m_debuginfo/readdwarf3.c
index a319bf3..afc7b8b 100644
--- a/coregrind/m_debuginfo/readdwarf3.c
+++ b/coregrind/m_debuginfo/readdwarf3.c
@@ -4689,7 +4689,6 @@
                = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.ndrw.5var",
                              ML_(dinfo_free),
                              sizeof(UInt) );
-            vg_assert(varparser.fndn_ix_Table);
          }
 
          if (VG_(clo_read_inline_info)) {
@@ -4699,7 +4698,6 @@
                = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.ndrw.5inl",
                              ML_(dinfo_free),
                              sizeof(UInt) );
-            vg_assert(inlparser.fndn_ix_Table);
          }
 
          /* Now read the one-and-only top-level DIE for this CU. */
@@ -4855,7 +4853,6 @@
          = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.ndrw.9",
                        ML_(dinfo_free), 
                        sizeof(TempVar*) );
-      vg_assert(dioff_lookup_tab);
 
       n = VG_(sizeXA)( tempvars );
       Word first_primary_var = 0;
diff --git a/coregrind/m_debuginfo/readmacho.c b/coregrind/m_debuginfo/readmacho.c
index 2750817..32be819 100644
--- a/coregrind/m_debuginfo/readmacho.c
+++ b/coregrind/m_debuginfo/readmacho.c
@@ -930,7 +930,6 @@
                     ML_(dinfo_zalloc), "di.readmacho.candsyms.1",
                     ML_(dinfo_free), sizeof(DiSym)
                  );
-      vg_assert(candSyms);
 
       // extern symbols
       read_symtab(candSyms,
diff --git a/coregrind/m_debuginfo/storage.c b/coregrind/m_debuginfo/storage.c
index 689a68f..efa04f3 100644
--- a/coregrind/m_debuginfo/storage.c
+++ b/coregrind/m_debuginfo/storage.c
@@ -1053,7 +1053,6 @@
       /* copy vars into it */
       vg_assert(first->vars);
       nyu->vars = VG_(cloneXA)( "di.storage.avta.1", first->vars );
-      vg_assert(nyu->vars);
       VG_(OSetGen_Insert)( scope, nyu );
       first = nyu;
    }
@@ -1082,7 +1081,6 @@
       /* copy vars into it */
       vg_assert(last->vars);
       nyu->vars = VG_(cloneXA)( "di.storage.avta.2", last->vars );
-      vg_assert(nyu->vars);
       VG_(OSetGen_Insert)( scope, nyu );
       last = nyu;
    }
@@ -1272,7 +1270,6 @@
       nyu->vars = VG_(newXA)( ML_(dinfo_zalloc), "di.storage.addVar.3",
                               ML_(dinfo_free),
                               sizeof(DiVariable) );
-      vg_assert(nyu->vars);
       VG_(OSetGen_Insert)( scope, nyu );
    }
 
diff --git a/coregrind/m_debuginfo/tytypes.c b/coregrind/m_debuginfo/tytypes.c
index abf6c18..d80876c 100644
--- a/coregrind/m_debuginfo/tytypes.c
+++ b/coregrind/m_debuginfo/tytypes.c
@@ -754,7 +754,6 @@
    XArray* xa = VG_(newXA)( ML_(dinfo_zalloc), "di.tytypes.dt.1",
                             ML_(dinfo_free),
                             sizeof(HChar) );
-   vg_assert(xa);
 
    ty = ML_(TyEnts__index_by_cuOff)(tyents, NULL, ty_cuOff);
 
diff --git a/coregrind/m_deduppoolalloc.c b/coregrind/m_deduppoolalloc.c
index 8a203e8..916f7e8 100644
--- a/coregrind/m_deduppoolalloc.c
+++ b/coregrind/m_deduppoolalloc.c
@@ -112,7 +112,7 @@
    ddpa->curpool = NULL;
    ddpa->curpool_limit = NULL;
    ddpa->curpool_free = NULL;
-   vg_assert(ddpa->pools);
+
    return ddpa;
 }
 
diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c
index e08cfc8..02bf0e4 100644
--- a/coregrind/m_errormgr.c
+++ b/coregrind/m_errormgr.c
@@ -388,7 +388,6 @@
       mode.  So generate it into TEXT. */
    text = VG_(newXA)( VG_(malloc), "errormgr.gen_suppression.1",
                       VG_(free), sizeof(HChar) );
-   vg_assert(text);
 
    /* Ok.  Generate the plain text version into TEXT. */
    VG_(xaprintf)(text, "{\n");
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
index a1e7a3a..131ac4f 100644
--- a/coregrind/m_main.c
+++ b/coregrind/m_main.c
@@ -2115,7 +2115,6 @@
    tl_assert(!addr2dihandle);
    addr2dihandle = VG_(newXA)( VG_(malloc), "main.vm.2",
                                VG_(free), sizeof(Addr_n_ULong) );
-   tl_assert(addr2dihandle);
 
 #  if defined(VGO_linux)
    { Addr* seg_starts;
diff --git a/coregrind/m_poolalloc.c b/coregrind/m_poolalloc.c
index 544239d..c9528e8 100644
--- a/coregrind/m_poolalloc.c
+++ b/coregrind/m_poolalloc.c
@@ -72,7 +72,7 @@
    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;
 }
 
diff --git a/coregrind/m_rangemap.c b/coregrind/m_rangemap.c
index 96c6537..dcb9b83 100644
--- a/coregrind/m_rangemap.c
+++ b/coregrind/m_rangemap.c
@@ -75,7 +75,6 @@
    rm->cc       = cc;
    rm->free_fn  = free_fn;
    rm->ranges = VG_(newXA)( alloc_fn, cc, free_fn, sizeof(Range) );
-   vg_assert(rm->ranges);
    /* Add the initial range */
    Range r;
    r.key_min = UWORD_MIN;
diff --git a/coregrind/m_xarray.c b/coregrind/m_xarray.c
index c440bfd..74ee631 100644
--- a/coregrind/m_xarray.c
+++ b/coregrind/m_xarray.c
@@ -38,9 +38,9 @@
 /* See pub_tool_xarray.h for details of what this is all about. */
 
 struct _XArray {
-   void* (*alloc) ( const HChar*, SizeT ); /* alloc fn (nofail) */
-   const HChar* cc;                 /* cost centre for alloc */
-   void  (*free) ( void* );         /* free fn */
+   void* (*alloc_fn) ( const HChar*, SizeT ); /* alloc fn (nofail) */
+   const HChar* cc;                    /* cost centre for alloc */
+   void  (*free_fn) ( void* );         /* free fn */
    Int   (*cmpFn) ( const void*, const void* ); /* cmp fn (may be NULL) */
    Word  elemSzB;   /* element size in bytes */
    void* arr;       /* pointer to elements */
@@ -55,7 +55,7 @@
                      void(*free_fn)(void*),
                      Word elemSzB )
 {
-   struct _XArray* xa;
+   XArray* xa;
    /* Implementation relies on Word being signed and (possibly)
       on SizeT being unsigned. */
    vg_assert( sizeof(Word) == sizeof(void*) );
@@ -66,10 +66,9 @@
    vg_assert(free_fn);
    vg_assert(elemSzB > 0);
    xa = alloc_fn( cc, sizeof(struct _XArray) );
-   vg_assert(xa);
-   xa->alloc     = alloc_fn;
+   xa->alloc_fn  = alloc_fn;
    xa->cc        = cc;
-   xa->free      = free_fn;
+   xa->free_fn   = free_fn;
    xa->cmpFn     = NULL;
    xa->elemSzB   = elemSzB;
    xa->usedsizeE = 0;
@@ -79,19 +78,17 @@
    return xa;
 }
 
-XArray* VG_(cloneXA)( const HChar* cc, XArray* xao )
+XArray* VG_(cloneXA)( const HChar* cc, XArray* xa )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
-   struct _XArray* nyu;
+   XArray* nyu;
    const HChar* nyu_cc;
    vg_assert(xa);
-   vg_assert(xa->alloc);
-   vg_assert(xa->free);
+   vg_assert(xa->alloc_fn);
+   vg_assert(xa->free_fn);
    vg_assert(xa->elemSzB >= 1);
    nyu_cc = cc ? cc : xa->cc;
-   nyu = xa->alloc( nyu_cc, sizeof(struct _XArray) );
-   if (!nyu)
-      return NULL;
+   nyu = xa->alloc_fn( nyu_cc, sizeof(struct _XArray) );
+
    /* Copy everything verbatim ... */
    *nyu = *xa;
    nyu->cc = nyu_cc;
@@ -104,46 +101,39 @@
          element is later added to it, unfortunately. */
       nyu->totsizeE = nyu->usedsizeE;
       /* and allocate .. */
-      nyu->arr = nyu->alloc( nyu->cc, nyu->totsizeE * nyu->elemSzB );
-      if (!nyu->arr) {
-         nyu->free(nyu);
-         return NULL;
-      }
+      nyu->arr = nyu->alloc_fn( nyu->cc, nyu->totsizeE * nyu->elemSzB );
       VG_(memcpy)( nyu->arr, xa->arr, nyu->totsizeE * nyu->elemSzB );
    }
    /* We're done! */
    return nyu;
 }
 
-void VG_(deleteXA) ( XArray* xao )
+void VG_(deleteXA) ( XArray* xa )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
-   vg_assert(xa->free);
+   vg_assert(xa->free_fn);
    if (xa->arr)
-      xa->free(xa->arr);
-   xa->free(xa);
+      xa->free_fn(xa->arr);
+   xa->free_fn(xa);
 }
 
-void VG_(setCmpFnXA) ( XArray* xao, XACmpFn_t compar )
+void VG_(setCmpFnXA) ( XArray* xa, XACmpFn_t compar )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    vg_assert(compar);
    xa->cmpFn  = compar;
    xa->sorted = False;
 }
 
-inline void* VG_(indexXA) ( XArray* xao, Word n )
+inline void* VG_(indexXA) ( XArray* xa, Word n )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    vg_assert(n >= 0);
    vg_assert(n < xa->usedsizeE);
    return ((char*)xa->arr) + n * xa->elemSzB;
 }
 
-static inline void ensureSpaceXA ( struct _XArray* xa )
+static inline void ensureSpaceXA ( XArray* xa )
 {
    if (xa->usedsizeE == xa->totsizeE) {
       void* tmp;
@@ -167,20 +157,18 @@
       if (0 && xa->totsizeE >= 10000) 
          VG_(printf)("addToXA: increasing from %ld to %ld\n", 
                      xa->totsizeE, newsz);
-      tmp = xa->alloc(xa->cc, newsz * xa->elemSzB);
-      vg_assert(tmp);
+      tmp = xa->alloc_fn(xa->cc, newsz * xa->elemSzB);
       if (xa->usedsizeE > 0) 
          VG_(memcpy)(tmp, xa->arr, xa->usedsizeE * xa->elemSzB);
       if (xa->arr)
-         xa->free(xa->arr);
+         xa->free_fn(xa->arr);
       xa->arr = tmp;
       xa->totsizeE = newsz;
    }
 }
 
-Word VG_(addToXA) ( XArray* xao, const void* elem )
+Word VG_(addToXA) ( XArray* xa, const void* elem )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    vg_assert(elem);
    vg_assert(xa->totsizeE >= 0);
@@ -195,10 +183,9 @@
    return xa->usedsizeE-1;
 }
 
-Word VG_(addBytesToXA) ( XArray* xao, const void* bytesV, Word nbytes )
+Word VG_(addBytesToXA) ( XArray* xa, const void* bytesV, Word nbytes )
 {
    Word r, i;
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    vg_assert(xa->elemSzB == 1);
    vg_assert(nbytes >= 0);
@@ -216,22 +203,20 @@
    return r;
 }
 
-void VG_(sortXA) ( XArray* xao )
+void VG_(sortXA) ( XArray* xa )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    vg_assert(xa->cmpFn);
    VG_(ssort)( xa->arr, xa->usedsizeE, xa->elemSzB, xa->cmpFn );
    xa->sorted = True;
 }
 
-Bool VG_(lookupXA_UNSAFE) ( XArray* xao, const void* key,
+Bool VG_(lookupXA_UNSAFE) ( XArray* xa, const void* key,
                             /*OUT*/Word* first, /*OUT*/Word* last,
                             Int(*cmpFn)(const void*, const void*) )
 {
    Word  lo, mid, hi, cres;
    void* midv;
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    lo = 0;
    hi = xa->usedsizeE-1;
@@ -264,35 +249,31 @@
    }
 }
 
-Bool VG_(lookupXA) ( XArray* xao, const void* key,
+Bool VG_(lookupXA) ( XArray* xa, const void* key,
                      /*OUT*/Word* first, /*OUT*/Word* last )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    vg_assert(xa->cmpFn);
    vg_assert(xa->sorted);
-   return VG_(lookupXA_UNSAFE)(xao, key, first, last, xa->cmpFn);
+   return VG_(lookupXA_UNSAFE)(xa, key, first, last, xa->cmpFn);
 }
 
-Word VG_(sizeXA) ( XArray* xao )
+Word VG_(sizeXA) ( XArray* xa )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    return xa->usedsizeE;
 }
 
-void VG_(dropTailXA) ( XArray* xao, Word n )
+void VG_(dropTailXA) ( XArray* xa, Word n )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    vg_assert(n >= 0);
    vg_assert(n <= xa->usedsizeE);
    xa->usedsizeE -= n;
 }
 
-void VG_(dropHeadXA) ( XArray* xao, Word n )
+void VG_(dropHeadXA) ( XArray* xa, Word n )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    vg_assert(n >= 0);
    vg_assert(n <= xa->usedsizeE);
@@ -311,9 +292,8 @@
    xa->usedsizeE -= n;
 }
 
-void VG_(removeIndexXA)( XArray* xao, Word n )
+void VG_(removeIndexXA)( XArray* xa, Word n )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    vg_assert(n >= 0);
    vg_assert(n < xa->usedsizeE);
@@ -325,9 +305,8 @@
    xa->usedsizeE--;
 }
 
-void VG_(insertIndexXA)( XArray* xao, Word n, const void* elem )
+void VG_(insertIndexXA)( XArray* xa, Word n, const void* elem )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    vg_assert(n >= 0);
    vg_assert(n <= xa->usedsizeE);
@@ -346,11 +325,10 @@
    xa->sorted = False;
 }
 
-void VG_(getContentsXA_UNSAFE)( XArray* xao,
+void VG_(getContentsXA_UNSAFE)( XArray* xa,
                                 /*OUT*/void** ctsP,
                                 /*OUT*/Word* usedP )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    *ctsP  = (void*)xa->arr;
    *usedP = xa->usedsizeE;
diff --git a/drd/drd_error.c b/drd/drd_error.c
index 12bfeff..7e6b5e1 100644
--- a/drd/drd_error.c
+++ b/drd/drd_error.c
@@ -171,8 +171,6 @@
    tl_assert(dri);
    tl_assert(dri->addr);
    tl_assert(dri->size > 0);
-   tl_assert(descr1);
-   tl_assert(descr2);
 
    (void) VG_(get_data_description)(descr1, descr2, dri->addr);
    /* If there's nothing in descr1/2, free them.  Why is it safe to to
diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c
index 4453954..673e413 100644
--- a/helgrind/hg_main.c
+++ b/helgrind/hg_main.c
@@ -2946,7 +2946,6 @@
                                  sizeof(Thread*) );
    }
 
-   tl_assert(bar->waiting);
    tl_assert(VG_(sizeXA)(bar->waiting) == 0);
    bar->initted   = True;
    bar->resizable = resizable == 1 ? True : False;
diff --git a/helgrind/libhb_core.c b/helgrind/libhb_core.c
index e1a18a7..3659aad 100644
--- a/helgrind/libhb_core.c
+++ b/helgrind/libhb_core.c
@@ -1846,7 +1846,6 @@
      = VG_(newXA)( HG_(zalloc),
                    "libhb.verydead_thread_table_init.1",
                    HG_(free), sizeof(ThrID) );
-   tl_assert(verydead_thread_table);
    VG_(setCmpFnXA)(verydead_thread_table, cmp__ThrID);
 }
 
@@ -2562,12 +2561,9 @@
 
 static void vts_tab_init ( void )
 {
-   vts_tab
-      = VG_(newXA)( HG_(zalloc), "libhb.vts_tab_init.1",
-                    HG_(free), sizeof(VtsTE) );
-   vts_tab_freelist
-      = VtsID_INVALID;
-   tl_assert(vts_tab);
+   vts_tab = VG_(newXA)( HG_(zalloc), "libhb.vts_tab_init.1",
+                         HG_(free), sizeof(VtsTE) );
+   vts_tab_freelist = VtsID_INVALID;
 }
 
 /* Add ii to the free list, checking that it looks out-of-use. */
@@ -3677,7 +3673,6 @@
    if (!thrid_to_thr_map) {
       thrid_to_thr_map = VG_(newXA)( HG_(zalloc), "libhb.Thr__new.4",
                                      HG_(free), sizeof(Thr*) );
-      tl_assert(thrid_to_thr_map);
    }
 
    if (thrid_counter >= ThrID_MAX_VALID) {
diff --git a/include/pub_tool_xarray.h b/include/pub_tool_xarray.h
index 086f0f4..73b9eab 100644
--- a/include/pub_tool_xarray.h
+++ b/include/pub_tool_xarray.h
@@ -51,8 +51,9 @@
 typedef Int (*XACmpFn_t)(const void *, const void *);
 
 /* Create new XArray, 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 XArray* VG_(newXA) ( void*(*alloc_fn)(const HChar*,SizeT), 
                             const HChar* cc,
                             void(*free_fn)(void*),
@@ -136,10 +137,9 @@
 
 /* Make a new, completely independent copy of the given XArray, using
    the existing allocation function to allocate the new space.
-   Returns NULL if the allocation function didn't manage to allocate
-   space (but did return NULL rather than merely abort.)  Space for
-   the clone (and all additions to it) is billed to 'cc' unless that
-   is NULL, in which case the parent's cost-center is used. */
+   Space for the clone (and all additions to it) is billed to 'cc' unless
+   that is NULL, in which case the parent's cost-center is used.
+   Ths function never returns NULL. */
 extern XArray* VG_(cloneXA)( const HChar* cc, XArray* xa );
 
 /* Get the raw array and size so callers can index it really fast.