]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add typedef Alloc_Fn_t/Free_Fn_t in pub_tool_basics.h, use them everywhere
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Fri, 18 Nov 2016 21:54:09 +0000 (21:54 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Fri, 18 Nov 2016 21:54:09 +0000 (21:54 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16138

13 files changed:
coregrind/m_deduppoolalloc.c
coregrind/m_oset.c
coregrind/m_poolalloc.c
coregrind/m_rangemap.c
coregrind/m_xarray.c
coregrind/m_xtree.c
include/pub_tool_basics.h
include/pub_tool_deduppoolalloc.h
include/pub_tool_oset.h
include/pub_tool_poolalloc.h
include/pub_tool_rangemap.h
include/pub_tool_xarray.h
include/pub_tool_xtree.h

index b8f10c72d60ba1a824200513a3aaa8791226d9ec..9b367218fc431547d173e91abda2d18e0cc22197 100644 (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);
index 3fd214f0f6e851e174df21ce2457932a0320f7af..134fa4308992745dddf6c7d746c8d1f424a116bc 100644 (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);
 }
index ed203ceeede45e5c663410d7679339d0efd0eaaf..473962fe2efe4e9457153afbda1650772fc09497 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_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)));
index b085d29681731b38beb990c271111881d9f029bc..37a6268313bbef0057742e0fe003d8413385f88d 100644 (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 .. */
index 3d48f1fca8d1dfc51b40a6ec5b9b44a7af02f0f8..467e45a4c8f9b000036e689ecb5034b5c18369d8 100644 (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;
index 5da5986c572d04b369b65dc694911c6287902bc2..275b8713b9217160abeb6ef2997d44f09d8af74c 100644 (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,
index 810e27ec8b2eb3b8dac696ca4c93c9f3802eb8c5..4ff9415755a68155d5b7ffbee577ee6c649d3c03 100644 (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, 
index 969c42cc989e10fd4351d024aa50462918312949..ed8fb3142ee48bf5703fb3efdd60e6998ebeab42 100644 (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.
index 0c9799720459dfd1552b1f8be31351c8862c6bf2..95bed77df565f7206c242fa574ec5f3c3e9fdfe0 100644 (file)
 
 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
index 549569fef817f60cef086feaa4cc3a3ec9db2bb1..35c9a47ef9e6939b4f64389b699701bb33ad145b 100644 (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. */
index 208b9dc73259798a7007574472a56937ea68e485..1b98b8e48f73f102b970f0a213f7b940e67be7b9 100644 (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. */
index 0e91dc00825b40598b2a400dc652e529f311f7a5..9eb9b43cee2033be68594a169b091daa0a2be3c9 100644 (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. */
index a976a38b8f495c8aa0d33b4885dd8d26fa28555b..24566433d0604c648958dd4202327f1763388d6d 100644 (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,