Tidy up m_oset.c
- Document that the allocation function must ot return NULL.
- As a conequence of the previous requirement the various Create and AllocNode
functions cannot return NULL. Remove pointless asserts at call sites.
- Remove documentation of undefined function CreateWithCmp.
- Names of library functions (such as 'free') are reserved as a are names
beginning with underscores. Don't use those.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14531 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c
index 75fa469..d3f646a 100644
--- a/coregrind/m_debuginfo/readelf.c
+++ b/coregrind/m_debuginfo/readelf.c
@@ -891,7 +891,6 @@
(OSetCmp_t)cmp_TempSymKey,
ML_(dinfo_zalloc), "di.respl.1",
ML_(dinfo_free) );
- vg_assert(oset);
/* Perhaps should start at i = 1; ELF docs suggest that entry
0 always denotes 'unknown symbol'. */
@@ -988,7 +987,6 @@
/* A new (name,addr) key. Add and continue. */
elem = VG_(OSetGen_AllocNode)(oset, sizeof(TempSym));
- vg_assert(elem);
elem->key = key;
elem->tocptr = GET_TOCPTR_AVMA(sym_avmas_really);
elem->size = sym_size;
diff --git a/coregrind/m_debuginfo/storage.c b/coregrind/m_debuginfo/storage.c
index 9c35c56..689a68f 100644
--- a/coregrind/m_debuginfo/storage.c
+++ b/coregrind/m_debuginfo/storage.c
@@ -1047,7 +1047,6 @@
vg_assert(first->aMin <= first->aMax);
/* create a new range */
nyu = VG_(OSetGen_AllocNode)( scope, sizeof(DiAddrRange) );
- vg_assert(nyu);
nyu->aMin = aMin;
nyu->aMax = tmp;
vg_assert(nyu->aMin <= nyu->aMax);
@@ -1077,7 +1076,6 @@
vg_assert(last->aMin <= last->aMax);
/* create a new range */
nyu = VG_(OSetGen_AllocNode)( scope, sizeof(DiAddrRange) );
- vg_assert(nyu);
nyu->aMin = tmp;
nyu->aMax = aMax;
vg_assert(nyu->aMin <= nyu->aMax);
@@ -1260,7 +1258,6 @@
ML_(cmp_for_DiAddrRange_range),
ML_(dinfo_zalloc), "di.storage.addVar.2",
ML_(dinfo_free) );
- vg_assert(scope);
if (0) VG_(printf)("create: scope = %p, adding at %ld\n",
scope, VG_(sizeXA)(di->varinfo));
VG_(addToXA)( di->varinfo, &scope );
@@ -1270,7 +1267,6 @@
All of these invariants get checked both add_var_to_arange
and after reading is complete, in canonicaliseVarInfo. */
nyu = VG_(OSetGen_AllocNode)( scope, sizeof(DiAddrRange) );
- vg_assert(nyu);
nyu->aMin = (Addr)0;
nyu->aMax = ~(Addr)0;
nyu->vars = VG_(newXA)( ML_(dinfo_zalloc), "di.storage.addVar.3",
diff --git a/coregrind/m_oset.c b/coregrind/m_oset.c
index 979245c..4499b6c 100644
--- a/coregrind/m_oset.c
+++ b/coregrind/m_oset.c
@@ -112,9 +112,9 @@
struct _OSet {
SizeT keyOff; // key offset
OSetCmp_t cmp; // compare a key and an element, or NULL
- OSetAlloc_t alloc; // allocator
- const HChar* cc; // cc for allocator
- OSetFree_t free; // deallocator
+ OSetAlloc_t alloc_fn; // allocator
+ const HChar* cc; // cost centre for allocator
+ OSetFree_t free_fn; // deallocator
PoolAlloc* node_pa; // (optional) pool allocator for nodes.
SizeT maxEltSize; // for node_pa, must be > 0. Otherwise unused.
Word nElems; // number of elements in the tree
@@ -285,9 +285,9 @@
/*--------------------------------------------------------------------*/
// The underscores avoid GCC complaints about overshadowing global names.
-AvlTree* VG_(OSetGen_Create)(PtrdiffT _keyOff, OSetCmp_t _cmp,
- OSetAlloc_t _alloc, const HChar* _cc,
- OSetFree_t _free)
+AvlTree* VG_(OSetGen_Create)(PtrdiffT keyOff, OSetCmp_t cmp,
+ OSetAlloc_t alloc_fn, const HChar* cc,
+ OSetFree_t free_fn)
{
AvlTree* t;
@@ -295,16 +295,16 @@
vg_assert(sizeof(AvlNode) == 3*sizeof(void*));
// Sanity check args
- vg_assert(_alloc);
- vg_assert(_free);
- if (!_cmp) vg_assert(0 == _keyOff); // If no cmp, offset must be zero
+ vg_assert(alloc_fn);
+ vg_assert(free_fn);
+ if (!cmp) vg_assert(0 == keyOff); // If no cmp, offset must be zero
- t = _alloc(_cc, sizeof(AvlTree));
- t->keyOff = _keyOff;
- t->cmp = _cmp;
- t->alloc = _alloc;
- t->cc = _cc;
- t->free = _free;
+ t = alloc_fn(cc, sizeof(AvlTree));
+ t->keyOff = keyOff;
+ t->cmp = cmp;
+ t->alloc_fn = alloc_fn;
+ t->cc = cc;
+ t->free_fn = free_fn;
t->node_pa = NULL;
t->maxEltSize = 0; // Just in case it would be wrongly used.
t->nElems = 0;
@@ -314,27 +314,25 @@
return t;
}
-AvlTree* VG_(OSetGen_Create_With_Pool)(PtrdiffT _keyOff, OSetCmp_t _cmp,
- OSetAlloc_t _alloc, const HChar* _cc,
- OSetFree_t _free,
- SizeT _poolSize,
- SizeT _maxEltSize)
+AvlTree* VG_(OSetGen_Create_With_Pool)(PtrdiffT keyOff, OSetCmp_t cmp,
+ OSetAlloc_t alloc_fn, const HChar* cc,
+ OSetFree_t free_fn,
+ SizeT poolSize,
+ SizeT maxEltSize)
{
AvlTree* t;
- t = VG_(OSetGen_Create) (_keyOff, _cmp,
- _alloc, _cc,
- _free);
+ t = VG_(OSetGen_Create) (keyOff, cmp, alloc_fn, cc, free_fn);
- vg_assert (_poolSize > 0);
- vg_assert (_maxEltSize > 0);
- t->maxEltSize = _maxEltSize;
+ vg_assert (poolSize > 0);
+ vg_assert (maxEltSize > 0);
+ t->maxEltSize = maxEltSize;
t->node_pa = VG_(newPA)(sizeof(AvlNode)
- + VG_ROUNDUP(_maxEltSize, sizeof(void*)),
- _poolSize,
- t->alloc,
- _cc,
- t->free);
+ + VG_ROUNDUP(maxEltSize, sizeof(void*)),
+ poolSize,
+ t->alloc_fn,
+ cc,
+ t->free_fn);
VG_(addRefPA) (t->node_pa);
return t;
@@ -346,12 +344,12 @@
vg_assert(os);
- t = os->alloc(os->cc, sizeof(AvlTree));
+ t = os->alloc_fn(os->cc, sizeof(AvlTree));
t->keyOff = os->keyOff;
t->cmp = os->cmp;
- t->alloc = os->alloc;
+ t->alloc_fn = os->alloc_fn;
t->cc = os->cc;
- t->free = os->free;
+ t->free_fn = os->free_fn;
t->node_pa = os->node_pa;
if (t->node_pa)
VG_(addRefPA) (t->node_pa);
@@ -363,10 +361,10 @@
return t;
}
-AvlTree* VG_(OSetWord_Create)(OSetAlloc_t _alloc, const HChar* _cc,
- OSetFree_t _free)
+AvlTree* VG_(OSetWord_Create)(OSetAlloc_t alloc_fn, const HChar* cc,
+ OSetFree_t free_fn)
{
- return VG_(OSetGen_Create)(/*keyOff*/0, /*cmp*/NULL, _alloc, _cc, _free);
+ return VG_(OSetGen_Create)(/*keyOff*/0, /*cmp*/NULL, alloc_fn, cc, free_fn);
}
// Destructor, frees up all memory held by remaining nodes.
@@ -407,7 +405,7 @@
if (has_node_pa)
VG_(freeEltPA) (t->node_pa, n);
else
- t->free(n);
+ t->free_fn(n);
sz++;
break;
}
@@ -416,7 +414,7 @@
}
/* Free the AvlTree itself. */
- t->free(t);
+ t->free_fn(t);
}
void VG_(OSetWord_Destroy)(AvlTree* t)
@@ -434,7 +432,7 @@
vg_assert(elemSize <= t->maxEltSize);
n = VG_(allocEltPA) (t->node_pa);
} else {
- n = t->alloc( t->cc, nodeSize );
+ n = t->alloc_fn( t->cc, nodeSize );
}
VG_(memset)(n, 0, nodeSize);
n->magic = OSET_MAGIC;
@@ -446,7 +444,7 @@
if (t->node_pa)
VG_(freeEltPA) (t->node_pa, node_of_elem (e));
else
- t->free( node_of_elem(e) );
+ t->free_fn( node_of_elem(e) );
}
/*--------------------------------------------------------------------*/
diff --git a/drd/drd_clientobj.c b/drd/drd_clientobj.c
index 444d84a..44234f9 100644
--- a/drd/drd_clientobj.c
+++ b/drd/drd_clientobj.c
@@ -60,7 +60,6 @@
tl_assert(s_clientobj_set == 0);
s_clientobj_set = VG_(OSetGen_Create)(0, 0, VG_(malloc),
"drd.clientobj.ci.1", VG_(free));
- tl_assert(s_clientobj_set);
}
/**
diff --git a/include/pub_tool_oset.h b/include/pub_tool_oset.h
index f696d64..def6fff 100644
--- a/include/pub_tool_oset.h
+++ b/include/pub_tool_oset.h
@@ -89,24 +89,23 @@
/*--- Creating and destroying OSets (UWord) ---*/
/*--------------------------------------------------------------------*/
-// * Create: allocates and initialises the OSet. Arguments:
-// - alloc The allocation function used internally for allocating the
-// OSet and all its nodes.
+// * Create: allocates and initialises the OSet. Never returns NULL.
+// Parameters:
+// - alloc_fn The allocation function used internally for allocating the
+// OSet and all its nodes. It must not return NULL (that is,
+// if it returns it must have succeeded.)
// - cc Cost centre string used by 'alloc'.
-// - free The deallocation function used internally for freeing nodes
+// - free_fn The deallocation function used internally for freeing nodes
// called by VG_(OSetWord_Destroy)().
//
-// * CreateWithCmp: like Create, but you specify your own comparison
-// function.
-//
// * Destroy: frees all nodes in the table, plus the memory used by
// the table itself. The passed-in function is called on each node first
// to allow the destruction of any attached resources; if NULL it is not
// called.
-extern OSet* VG_(OSetWord_Create) ( OSetAlloc_t alloc, const HChar* cc,
- OSetFree_t _free );
-extern void VG_(OSetWord_Destroy) ( OSet* os );
+extern OSet* VG_(OSetWord_Create) ( OSetAlloc_t alloc_fn, const HChar* cc,
+ OSetFree_t free_fn );
+extern void VG_(OSetWord_Destroy) ( OSet* os );
/*--------------------------------------------------------------------*/
/*--- Operations on OSets (UWord) ---*/
@@ -160,17 +159,20 @@
/*--- Creating and destroying OSets and OSet members (Gen) ---*/
/*--------------------------------------------------------------------*/
-// * Create: allocates and initialises the OSet. Arguments:
+// * Create: allocates and initialises the OSet. Never returns NULL.
+// Parameters:
// - keyOff The offset of the key within the element.
// - cmp The comparison function between keys and elements, or NULL
// if the OSet should use fast comparisons.
-// - alloc The allocation function used for allocating the OSet itself;
+// - alloc_fn The allocation function used for allocating the OSet itself;
+// It must not return NULL (that is, if it returns it must
+// have succeeded.)
// If a pool allocator is used, it's called to allocate pool of
// nodes.
// If no pool allocator is used, it's called for each
// invocation of VG_(OSetGen_AllocNode)().
// - cc Cost centre string used by 'alloc'.
-// - free If no pool allocator is used, this is the deallocation
+// - free_fn If no pool allocator is used, this is the deallocation
// function used by VG_(OSetGen_FreeNode)() and
// VG_(OSetGen_Destroy)().
// If a pool allocator is used, the memory used by the nodes is
@@ -202,14 +204,14 @@
// lead to assertions in Valgrind's allocator.
extern OSet* VG_(OSetGen_Create) ( PtrdiffT keyOff, OSetCmp_t cmp,
- OSetAlloc_t alloc, const HChar* cc,
- OSetFree_t _free);
+ OSetAlloc_t alloc_fn, const HChar* cc,
+ OSetFree_t free_fn);
extern OSet* VG_(OSetGen_Create_With_Pool) ( PtrdiffT keyOff, OSetCmp_t cmp,
- OSetAlloc_t alloc,
+ OSetAlloc_t alloc_fn,
const HChar* cc,
- OSetFree_t _free,
+ OSetFree_t free_fn,
SizeT poolSize,
SizeT maxEltSize);
// Same as VG_(OSetGen_Create) but created OSet will use a pool allocator to
diff --git a/memcheck/mc_main.c b/memcheck/mc_main.c
index 69370eb..5526833 100644
--- a/memcheck/mc_main.c
+++ b/memcheck/mc_main.c
@@ -578,7 +578,6 @@
a &= ~(Addr)0xFFFF;
nyu = (AuxMapEnt*) VG_(OSetGen_AllocNode)( auxmap_L2, sizeof(AuxMapEnt) );
- tl_assert(nyu);
nyu->base = a;
nyu->sm = &sm_distinguished[SM_DIST_NOACCESS];
VG_(OSetGen_Insert)( auxmap_L2, nyu );
@@ -2414,7 +2413,6 @@
= VG_(OSetGen_Create)( offsetof(OCacheLine,tag),
NULL, /* fast cmp */
ocacheL2_malloc, "mc.ioL2", ocacheL2_free);
- tl_assert(ocacheL2);
stats__ocacheL2_n_nodes = 0;
}
@@ -2450,7 +2448,6 @@
OCacheLine* copy;
tl_assert(is_valid_oc_tag(line->tag));
copy = VG_(OSetGen_AllocNode)( ocacheL2, sizeof(OCacheLine) );
- tl_assert(copy);
*copy = *line;
stats__ocacheL2_refs++;
VG_(OSetGen_Insert)( ocacheL2, copy );