Add typedef Alloc_Fn_t/Free_Fn_t in pub_tool_basics.h, use them everywhere

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16138
This commit is contained in:
Philippe Waroquiers 2016-11-18 21:54:09 +00:00
parent 8ec0762735
commit 471900460d
13 changed files with 60 additions and 54 deletions

View File

@ -43,9 +43,9 @@ struct _DedupPoolAlloc {
SizeT fixedSzb; /* If using VG_(allocFixedEltDedupPA), size of elements */
Bool strPA; /* True if this is a string dedup pool */
SizeT eltAlign;
void* (*alloc_fn)(const HChar*, SizeT); /* pool allocator */
Alloc_Fn_t alloc_fn; /* pool allocator */
const HChar* cc; /* pool allocator's cost centre */
void (*free_fn)(void*); /* pool allocator's deallocation function */
Free_Fn_t free_fn; /* 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. */
@ -84,9 +84,9 @@ typedef
DedupPoolAlloc* VG_(newDedupPA) ( SizeT poolSzB,
SizeT eltAlign,
void* (*alloc_fn)(const HChar*, SizeT),
Alloc_Fn_t alloc_fn,
const HChar* cc,
void (*free_fn)(void*) )
Free_Fn_t free_fn )
{
DedupPoolAlloc* ddpa;
vg_assert(poolSzB >= eltAlign);

View File

@ -112,9 +112,9 @@ struct _OSetNode {
struct _OSet {
SizeT keyOff; // key offset
OSetCmp_t cmp; // compare a key and an element, or NULL
OSetAlloc_t alloc_fn; // allocator
Alloc_Fn_t alloc_fn; // allocator
const HChar* cc; // cost centre for allocator
OSetFree_t free_fn; // deallocator
Free_Fn_t free_fn; // deallocator
PoolAlloc* node_pa; // (optional) pool allocator for nodes.
SizeT maxEltSize; // for node_pa, must be > 0. Otherwise unused.
UInt nElems; // number of elements in the tree
@ -286,8 +286,8 @@ static inline Bool stackPop(AvlTree* t, AvlNode** n, Int* i)
// The underscores avoid GCC complaints about overshadowing global names.
AvlTree* VG_(OSetGen_Create)(PtrdiffT keyOff, OSetCmp_t cmp,
OSetAlloc_t alloc_fn, const HChar* cc,
OSetFree_t free_fn)
Alloc_Fn_t alloc_fn, const HChar* cc,
Free_Fn_t free_fn)
{
AvlTree* t;
@ -315,8 +315,8 @@ AvlTree* VG_(OSetGen_Create)(PtrdiffT keyOff, OSetCmp_t cmp,
}
AvlTree* VG_(OSetGen_Create_With_Pool)(PtrdiffT keyOff, OSetCmp_t cmp,
OSetAlloc_t alloc_fn, const HChar* cc,
OSetFree_t free_fn,
Alloc_Fn_t alloc_fn, const HChar* cc,
Free_Fn_t free_fn,
SizeT poolSize,
SizeT maxEltSize)
{
@ -361,8 +361,8 @@ AvlTree* VG_(OSetGen_EmptyClone) (const AvlTree* os)
return t;
}
AvlTree* VG_(OSetWord_Create)(OSetAlloc_t alloc_fn, const HChar* cc,
OSetFree_t free_fn)
AvlTree* VG_(OSetWord_Create)(Alloc_Fn_t alloc_fn, const HChar* cc,
Free_Fn_t free_fn)
{
return VG_(OSetGen_Create)(/*keyOff*/0, /*cmp*/NULL, alloc_fn, cc, free_fn);
}

View 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_fn)(const HChar*, SizeT); /* pool allocator */
const HChar* cc; /* pool allocator's cost centre */
void (*free_fn)(void*); /* pool allocator's free-er */
Alloc_Fn_t alloc_fn; /* pool allocator */
const HChar* cc; /* pool allocator's cost centre */
Free_Fn_t free_fn; /* 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,9 +50,9 @@ struct _PoolAlloc {
PoolAlloc* VG_(newPA) ( UWord elemSzB,
UWord nPerPool,
void* (*alloc_fn)(const HChar*, SizeT),
Alloc_Fn_t alloc_fn,
const HChar* cc,
void (*free_fn)(void*) )
Free_Fn_t free_fn )
{
PoolAlloc* pa;
vg_assert(0 == (elemSzB % sizeof(UWord)));

View File

@ -48,9 +48,9 @@ typedef
struct _RangeMap {
void* (*alloc_fn) ( const HChar*, SizeT ); /* alloc fn (nofail) */
Alloc_Fn_t alloc_fn; /* alloc fn (nofail) */
const HChar* cc; /* cost centre for alloc */
void (*free_fn) ( void* ); /* free fn */
Free_Fn_t free_fn; /* free fn */
XArray* ranges;
};
@ -62,9 +62,9 @@ static void split_at ( /*MOD*/RangeMap* rm, UWord key );
static void show ( const RangeMap* rm );
RangeMap* VG_(newRangeMap) ( void*(*alloc_fn)(const HChar*,SizeT),
RangeMap* VG_(newRangeMap) ( Alloc_Fn_t alloc_fn,
const HChar* cc,
void(*free_fn)(void*),
Free_Fn_t free_fn,
UWord initialVal )
{
/* check user-supplied info .. */

View File

@ -38,9 +38,9 @@
/* See pub_tool_xarray.h for details of what this is all about. */
struct _XArray {
void* (*alloc_fn) ( const HChar*, SizeT ); /* alloc fn (nofail) */
Alloc_Fn_t alloc_fn; /* alloc fn (nofail) */
const HChar* cc; /* cost centre for alloc */
void (*free_fn) ( void* ); /* free fn */
Free_Fn_t free_fn; /* free fn */
Int (*cmpFn) ( const void*, const void* ); /* cmp fn (may be NULL) */
Word elemSzB; /* element size in bytes */
void* arr; /* pointer to elements */
@ -50,9 +50,9 @@ struct _XArray {
};
XArray* VG_(newXA) ( void*(*alloc_fn)(const HChar*,SizeT),
XArray* VG_(newXA) ( Alloc_Fn_t alloc_fn,
const HChar* cc,
void(*free_fn)(void*),
Free_Fn_t free_fn,
Word elemSzB )
{
XArray* xa;

View File

@ -73,9 +73,9 @@ typedef
struct _XT_shared {
UWord nrRef; /* nr of XTrees referencing this shared memory. */
void* (*alloc_fn)( const HChar*, SizeT ); /* alloc fn (nofail) */
Alloc_Fn_t alloc_fn; /* alloc fn (nofail) */
const HChar* cc; /* cost centre for alloc */
void (*free_fn)( void* ); /* free fn */
Free_Fn_t free_fn; /* free fn */
/* The data associated to each ec is stored in 2 arrays:
an xec array, shared between an xt and all its snapshots.
@ -102,7 +102,7 @@ typedef
(with the index ecu/4). */
#define NO_OFFSET 0xffffffff
static XT_shared* new_XT_shared (void* (*alloc_fn)(const HChar*, SizeT),
static XT_shared* new_XT_shared (Alloc_Fn_t alloc_fn,
const HChar* cc,
void (*free_fn)(void*))
{
@ -208,9 +208,9 @@ static UWord release_XT_shared(XT_shared* shared)
struct _XTree {
void* (*alloc_fn)( const HChar*, SizeT ); /* alloc fn (nofail) */
Alloc_Fn_t alloc_fn; /* alloc fn (nofail) */
const HChar* cc; /* cost centre for alloc */
void (*free_fn)( void* ); /* free fn */
Free_Fn_t free_fn; /* free fn */
Word dataSzB; /* data size in bytes */
XT_init_data_t init_data_fn;
XT_add_data_t add_data_fn;
@ -224,9 +224,9 @@ struct _XTree {
};
XTree* VG_(XT_create) ( void*(*alloc_fn)(const HChar*, SizeT),
XTree* VG_(XT_create) ( Alloc_Fn_t alloc_fn,
const HChar* cc,
void(*free_fn) (void*),
Free_Fn_t free_fn,
Word dataSzB,
XT_init_data_t init_data_fn,
XT_add_data_t add_data_fn,

View File

@ -129,6 +129,17 @@ typedef struct { UWord uw1; UWord uw2; } UWordPair;
/* ThreadIds are simply indices into the VG_(threads)[] array. */
typedef UInt ThreadId;
/* Many data structures need to allocate and release memory.
The allocation/release functions must be provided by the caller.
The Alloc_Fn_t function must allocate a chunk of memory of size szB.
cc is the Cost Centre for this allocated memory. This constant string
is used to provide Valgrind's heap profiling, activated by
--profile-heap=no|yes.
The corresponding Free_Fn_t frees the memory chunk p. */
typedef void* (*Alloc_Fn_t) ( const HChar* cc, SizeT szB );
typedef void (*Free_Fn_t) ( void* p );
/* An abstraction of syscall return values.
Linux/MIPS32 and Linux/MIPS64:
When _isError == False,

View File

@ -93,9 +93,9 @@ typedef struct _DedupPoolAlloc DedupPoolAlloc;
This function never returns NULL. */
extern DedupPoolAlloc* VG_(newDedupPA) ( SizeT poolSzB,
SizeT eltAlign,
void* (*alloc)(const HChar*, SizeT),
Alloc_Fn_t alloc_fn,
const HChar* cc,
void (*free_fn)(void*) );
Free_Fn_t free_fn );
/* Allocates or retrieve element from ddpa with eltSzB bytes to store elt.
This function never returns NULL.

View File

@ -77,13 +77,8 @@
typedef struct _OSet OSet;
// - Cmp: returns -1, 0 or 1 if key is <, == or > elem.
// - Alloc: allocates a chunk of memory.
// - Free: frees a chunk of memory allocated with Alloc.
// - OSetCmp_t: returns -1, 0 or 1 if key is <, == or > elem.
typedef Word (*OSetCmp_t) ( const void* key, const void* elem );
typedef void* (*OSetAlloc_t) ( const HChar* cc, SizeT szB );
typedef void (*OSetFree_t) ( void* p );
/*--------------------------------------------------------------------*/
/*--- Creating and destroying OSets (UWord) ---*/
@ -103,8 +98,8 @@ typedef void (*OSetFree_t) ( void* p );
// to allow the destruction of any attached resources; if NULL it is not
// called.
extern OSet* VG_(OSetWord_Create) ( OSetAlloc_t alloc_fn, const HChar* cc,
OSetFree_t free_fn );
extern OSet* VG_(OSetWord_Create) ( Alloc_Fn_t alloc_fn, const HChar* cc,
Free_Fn_t free_fn );
extern void VG_(OSetWord_Destroy) ( OSet* os );
/*--------------------------------------------------------------------*/
@ -204,14 +199,14 @@ extern Bool VG_(OSetWord_Next) ( OSet* os, /*OUT*/UWord* val );
// lead to assertions in Valgrind's allocator.
extern OSet* VG_(OSetGen_Create) ( PtrdiffT keyOff, OSetCmp_t cmp,
OSetAlloc_t alloc_fn, const HChar* cc,
OSetFree_t free_fn);
Alloc_Fn_t alloc_fn, const HChar* cc,
Free_Fn_t free_fn);
extern OSet* VG_(OSetGen_Create_With_Pool) ( PtrdiffT keyOff, OSetCmp_t cmp,
OSetAlloc_t alloc_fn,
Alloc_Fn_t alloc_fn,
const HChar* cc,
OSetFree_t free_fn,
Free_Fn_t free_fn,
SizeT poolSize,
SizeT maxEltSize);
// Same as VG_(OSetGen_Create) but created OSet will use a pool allocator to

View File

@ -56,9 +56,9 @@ typedef struct _PoolAlloc PoolAlloc;
This function never returns NULL. */
extern PoolAlloc* VG_(newPA) ( UWord elemSzB,
UWord nPerPool,
void* (*alloc)(const HChar*, SizeT),
Alloc_Fn_t alloc_fn,
const HChar* cc,
void (*free_fn)(void*) );
Free_Fn_t free_fn );
/* Free all memory associated with a PoolAlloc. */

View File

@ -47,9 +47,9 @@ typedef struct _RangeMap RangeMap;
succeeded.) The new array will contain a single range covering the
entire key space, which will be bound to the value |initialVal|.
This function never returns NULL. */
RangeMap* VG_(newRangeMap) ( void*(*alloc_fn)(const HChar*,SizeT),
RangeMap* VG_(newRangeMap) ( Alloc_Fn_t alloc_fn,
const HChar* cc,
void(*free_fn)(void*),
Free_Fn_t free_fn,
UWord initialVal );
/* Free all memory associated with a RangeMap. */

View File

@ -54,9 +54,9 @@ typedef Int (*XACmpFn_t)(const void *, const void *);
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),
extern XArray* VG_(newXA) ( Alloc_Fn_t alloc_fn,
const HChar* cc,
void(*free_fn)(void*),
Free_Fn_t free_fn,
Word elemSzB );
/* Free all memory associated with an XArray. */

View File

@ -96,9 +96,9 @@ typedef void (*XT_filter_IPs_t) (Addr* ips, Int n_ips,
alloc_fn must not return NULL (that is, if it returns it must have
succeeded.).
See respective typedef for *_fn arguments. */
extern XTree* VG_(XT_create) ( void*(*alloc_fn)(const HChar*, SizeT),
extern XTree* VG_(XT_create) ( Alloc_Fn_t alloc_fn,
const HChar* cc,
void(*free_fn) (void*),
Free_Fn_t free_fn,
Word dataSzB,
XT_init_data_t init_data_fn,
XT_add_data_t add_data_fn,