From: Florian Krohm Date: Sat, 18 Oct 2014 16:17:13 +0000 (+0000) Subject: Constify m_oset, m_sparsewa, and m_wordfm. X-Git-Tag: svn/VALGRIND_3_11_0~908 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9959f9acb0c00f9a361789fdd968e9b8fefd3c54;p=thirdparty%2Fvalgrind.git Constify m_oset, m_sparsewa, and m_wordfm. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14640 --- diff --git a/coregrind/m_oset.c b/coregrind/m_oset.c index 4499b6c68d..d1b1729366 100644 --- a/coregrind/m_oset.c +++ b/coregrind/m_oset.c @@ -165,13 +165,13 @@ void* elem_of_node_no_check(const AvlNode *n) } static inline -void* slow_key_of_node(AvlTree* t, AvlNode* n) +void* slow_key_of_node(const AvlTree* t, const AvlNode* n) { return (void*)((Addr)elem_of_node(n) + t->keyOff); } static inline -void* fast_key_of_node(AvlNode* n) +void* fast_key_of_node(const AvlNode* n) { return elem_of_node(n); } @@ -338,7 +338,7 @@ AvlTree* VG_(OSetGen_Create_With_Pool)(PtrdiffT keyOff, OSetCmp_t cmp, return t; } -AvlTree* VG_(OSetGen_EmptyClone) (AvlTree* os) +AvlTree* VG_(OSetGen_EmptyClone) (const AvlTree* os) { AvlTree* t; @@ -423,7 +423,7 @@ void VG_(OSetWord_Destroy)(AvlTree* t) } // Allocate and initialise a new node. -void* VG_(OSetGen_AllocNode)(AvlTree* t, SizeT elemSize) +void* VG_(OSetGen_AllocNode)(const AvlTree* t, SizeT elemSize) { AvlNode* n; Int nodeSize = sizeof(AvlNode) + elemSize; @@ -439,7 +439,7 @@ void* VG_(OSetGen_AllocNode)(AvlTree* t, SizeT elemSize) return elem_of_node(n); } -void VG_(OSetGen_FreeNode)(AvlTree* t, void* e) +void VG_(OSetGen_FreeNode)(const AvlTree* t, void* e) { if (t->node_pa) VG_(freeEltPA) (t->node_pa, node_of_elem (e)); @@ -451,7 +451,7 @@ void VG_(OSetGen_FreeNode)(AvlTree* t, void* e) /*--- Insertion ---*/ /*--------------------------------------------------------------------*/ -static inline Word cmp_key_root(AvlTree* t, AvlNode* n) +static inline Word cmp_key_root(const AvlTree* t, const AvlNode* n) { return t->cmp ? slow_cmp(t, slow_key_of_node(t, n), t->root) @@ -633,7 +633,7 @@ Bool VG_(OSetGen_Contains)(const AvlTree* t, const void* k) return (NULL != VG_(OSetGen_Lookup)(t, k)); } -Bool VG_(OSetWord_Contains)(AvlTree* t, UWord val) +Bool VG_(OSetWord_Contains)(const AvlTree* t, UWord val) { return (NULL != VG_(OSetGen_Lookup)(t, &val)); } @@ -646,7 +646,7 @@ static Bool avl_removeroot(AvlTree* t); // Remove an already-selected node n from the AVL tree t. // Returns True if the depth of the tree has shrunk. -static Bool avl_remove(AvlTree* t, AvlNode* n) +static Bool avl_remove(AvlTree* t, const AvlNode* n) { Bool ch; Word cmpres = cmp_key_root(t, n); @@ -918,13 +918,13 @@ Word VG_(OSetGen_Size)(const AvlTree* t) return t->nElems; } -Word VG_(OSetWord_Size)(AvlTree* t) +Word VG_(OSetWord_Size)(const AvlTree* t) { return VG_(OSetGen_Size)(t); } -static void OSet_Print2( AvlTree* t, AvlNode* n, - HChar*(*strElem)(void *), Int p ) +static void OSet_Print2( const AvlTree* t, const AvlNode* n, + const HChar*(*strElem)(const void *), Int p ) { // This is a recursive in-order traversal. Int q = p; @@ -936,8 +936,8 @@ static void OSet_Print2( AvlTree* t, AvlNode* n, } __attribute__((unused)) -static void OSet_Print( AvlTree* t, const HChar *where, - HChar*(*strElem)(void *) ) +static void OSet_Print( const AvlTree* t, const HChar *where, + const HChar*(*strElem)(const void *) ) { VG_(printf)("-- start %s ----------------\n", where); OSet_Print2(t, t->root, strElem, 0); diff --git a/coregrind/m_sparsewa.c b/coregrind/m_sparsewa.c index 666754204f..94a3cec2dd 100644 --- a/coregrind/m_sparsewa.c +++ b/coregrind/m_sparsewa.c @@ -89,7 +89,7 @@ struct _SparseWA { //////// SWA helper functions (bitarray) -static inline UWord swa_bitarray_read ( UChar* arr, UWord ix ) { +static inline UWord swa_bitarray_read ( const UChar* arr, UWord ix ) { UWord bix = ix >> 3; UWord off = ix & 7; return (arr[bix] >> off) & 1; @@ -146,7 +146,7 @@ static void swa_POP ( SparseWA* swa, //////// SWA helper functions (allocation) -static LevelN* swa_new_LevelN ( SparseWA* swa, Int level ) +static LevelN* swa_new_LevelN ( const SparseWA* swa, Int level ) { LevelN* levelN = swa->alloc_nofail( swa->cc, sizeof(LevelN) ); VG_(memset)(levelN, 0, sizeof(*levelN)); @@ -155,7 +155,7 @@ static LevelN* swa_new_LevelN ( SparseWA* swa, Int level ) return levelN; } -static Level0* swa_new_Level0 ( SparseWA* swa ) +static Level0* swa_new_Level0 ( const SparseWA* swa ) { Level0* level0 = swa->alloc_nofail( swa->cc, sizeof(Level0) ); VG_(memset)(level0, 0, sizeof(*level0)); @@ -273,7 +273,7 @@ void VG_(deleteSWA) ( SparseWA* swa ) } -Bool VG_(lookupSWA) ( SparseWA* swa, +Bool VG_(lookupSWA) ( const SparseWA* swa, /*OUT*/UWord* keyP, /*OUT*/UWord* valP, UWord key ) { @@ -432,12 +432,12 @@ Bool VG_(delFromSWA) ( SparseWA* swa, } -static UWord swa_sizeSWA_wrk ( void* nd ) +static UWord swa_sizeSWA_wrk ( const void* nd ) { Int i; - if (*(UWord*)nd == LevelN_MAGIC) { + if (*(const UWord*)nd == LevelN_MAGIC) { UWord sum = 0; - LevelN* levelN = (LevelN*)nd; + const LevelN* levelN = nd; for (i = 0; i < 256; i++) { if (levelN->child[i]) { sum += swa_sizeSWA_wrk( levelN->child[i] ); @@ -445,13 +445,13 @@ static UWord swa_sizeSWA_wrk ( void* nd ) } return sum; } else { - Level0* level0; - vg_assert(*(UWord*)nd == Level0_MAGIC); - level0 = (Level0*)nd; + const Level0* level0; + vg_assert(*(const UWord*)nd == Level0_MAGIC); + level0 = nd; return level0->nInUse; } } -UWord VG_(sizeSWA) ( SparseWA* swa ) +UWord VG_(sizeSWA) ( const SparseWA* swa ) { if (swa->root) return swa_sizeSWA_wrk ( swa->root ); diff --git a/coregrind/m_wordfm.c b/coregrind/m_wordfm.c index 0685c7f7bf..30cd6ad6f0 100644 --- a/coregrind/m_wordfm.c +++ b/coregrind/m_wordfm.c @@ -136,7 +136,7 @@ static void avl_nasty ( AvlNode* root ) } /* Find size of a non-NULL tree. */ -static UWord size_avl_nonNull ( AvlNode* nd ) +static UWord size_avl_nonNull ( const AvlNode* nd ) { return 1 + (nd->child[0] ? size_avl_nonNull(nd->child[0]) : 0) + (nd->child[1] ? size_avl_nonNull(nd->child[1]) : 0); @@ -417,7 +417,7 @@ AvlNode* avl_find_node ( AvlNode* t, Word k, Word(*kCmp)(UWord,UWord) ) } static -Bool avl_find_bounds ( AvlNode* t, +Bool avl_find_bounds ( const AvlNode* t, /*OUT*/UWord* kMinP, /*OUT*/UWord* vMinP, /*OUT*/UWord* kMaxP, /*OUT*/UWord* vMaxP, UWord minKey, UWord minVal, @@ -499,7 +499,7 @@ static inline Bool stackPop(WordFM* fm, AvlNode** n, Int* i) } static -AvlNode* avl_dopy ( AvlNode* nd, +AvlNode* avl_dopy ( const AvlNode* nd, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord), void*(alloc_nofail)(const HChar*,SizeT), @@ -644,7 +644,7 @@ Bool VG_(delFromFM) ( WordFM* fm, } // Look up in fm, assigning found key & val at spec'd addresses -Bool VG_(lookupFM) ( WordFM* fm, +Bool VG_(lookupFM) ( const WordFM* fm, /*OUT*/UWord* keyP, /*OUT*/UWord* valP, UWord key ) { AvlNode* node = avl_find_node( fm->root, key, fm->kCmp ); @@ -660,7 +660,7 @@ Bool VG_(lookupFM) ( WordFM* fm, } // See comment in pub_tool_wordfm.h for explanation -Bool VG_(findBoundsFM)( WordFM* fm, +Bool VG_(findBoundsFM)( const WordFM* fm, /*OUT*/UWord* kMinP, /*OUT*/UWord* vMinP, /*OUT*/UWord* kMaxP, /*OUT*/UWord* vMaxP, UWord minKey, UWord minVal, @@ -677,14 +677,14 @@ Bool VG_(findBoundsFM)( WordFM* fm, } // See comment in pub_tool_wordfm.h for performance warning -UWord VG_(sizeFM) ( WordFM* fm ) +UWord VG_(sizeFM) ( const WordFM* fm ) { // Hmm, this is a bad way to do this return fm->root ? size_avl_nonNull( fm->root ) : 0; } // NB UNTESTED! TEST BEFORE USE! -//Bool VG_(isEmptyFM)( WordFM* fm ) +//Bool VG_(isEmptyFM)( const WordFM* fm ) //{ // return fm->root ? False : True; //} @@ -793,7 +793,8 @@ void VG_(doneIterFM) ( WordFM* fm ) { } -WordFM* VG_(dopyFM) ( WordFM* fm, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) ) +WordFM* VG_(dopyFM) ( WordFM* fm, UWord(*dopyK)(UWord), + UWord(*dopyV)(UWord) ) { WordFM* nyu; @@ -862,7 +863,7 @@ void VG_(addToBag)( WordBag* bag, UWord w ) } } -UWord VG_(elemBag) ( WordBag* bag, UWord w ) +UWord VG_(elemBag) ( const WordBag* bag, UWord w ) { UWord key, count; if (VG_(lookupFM)( bag->fm, &key, &count, w)) { @@ -874,12 +875,12 @@ UWord VG_(elemBag) ( WordBag* bag, UWord w ) } } -UWord VG_(sizeUniqueBag) ( WordBag* bag ) +UWord VG_(sizeUniqueBag) ( const WordBag* bag ) { return VG_(sizeFM)( bag->fm ); } -static UWord sizeTotalBag_wrk ( AvlNode* nd ) +static UWord sizeTotalBag_wrk ( const AvlNode* nd ) { /* unchecked pre: nd is non-NULL */ UWord w = nd->val; @@ -890,7 +891,7 @@ static UWord sizeTotalBag_wrk ( AvlNode* nd ) w += sizeTotalBag_wrk(nd->child[1]); return w; } -UWord VG_(sizeTotalBag)( WordBag* bag ) +UWord VG_(sizeTotalBag)( const WordBag* bag ) { if (bag->fm->root) return sizeTotalBag_wrk(bag->fm->root); @@ -916,12 +917,12 @@ Bool VG_(delFromBag)( WordBag* bag, UWord w ) } } -Bool VG_(isEmptyBag)( WordBag* bag ) +Bool VG_(isEmptyBag)( const WordBag* bag ) { return VG_(sizeFM)(bag->fm) == 0; } -Bool VG_(isSingletonTotalBag)( WordBag* bag ) +Bool VG_(isSingletonTotalBag)( const WordBag* bag ) { AvlNode* nd; if (VG_(sizeFM)(bag->fm) != 1) @@ -933,7 +934,7 @@ Bool VG_(isSingletonTotalBag)( WordBag* bag ) return nd->val == 1; } -UWord VG_(anyElementOfBag)( WordBag* bag ) +UWord VG_(anyElementOfBag)( const WordBag* bag ) { /* Return an arbitrarily chosen element in the bag. We might as well return the one at the root of the underlying AVL tree. */ diff --git a/include/pub_tool_oset.h b/include/pub_tool_oset.h index def6fffc5c..a52606cf65 100644 --- a/include/pub_tool_oset.h +++ b/include/pub_tool_oset.h @@ -147,9 +147,9 @@ extern void VG_(OSetWord_Destroy) ( OSet* os ); // they will return False if VG_(OSetWord_Next)() is called without an // intervening call to VG_(OSetWord_ResetIter)(). -extern Word VG_(OSetWord_Size) ( OSet* os ); +extern Word VG_(OSetWord_Size) ( const OSet* os ); extern void VG_(OSetWord_Insert) ( OSet* os, UWord val ); -extern Bool VG_(OSetWord_Contains) ( OSet* os, UWord val ); +extern Bool VG_(OSetWord_Contains) ( const OSet* os, UWord val ); extern Bool VG_(OSetWord_Remove) ( OSet* os, UWord val ); extern void VG_(OSetWord_ResetIter) ( OSet* os ); extern Bool VG_(OSetWord_Next) ( OSet* os, /*OUT*/UWord* val ); @@ -225,11 +225,11 @@ extern OSet* VG_(OSetGen_Create_With_Pool) ( PtrdiffT keyOff, OSetCmp_t cmp, // always <= than a (small) maximum value. // In such a case, allocating the nodes in pools reduces significantly // the memory overhead needed by each node. -// When a node is freed (i.e. OsetGen_Freenode is called), the node is +// When a node is freed (i.e. OSetGen_Freenode is called), the node is // put back in the pool allocator free list (for sub-sequent re-use by -// Osetgen_Allocnode). Note that the pool memory is only released when +// OSetGen_AllocNode). Note that the pool memory is only released when // the pool is destroyed : calls to VG_(OSetGen_Free) do not cause -// any calls to OsetFree_t _free function. +// any calls to OSetFree_t _free function. // If there are several OSet managing similar such elements, it might be // interesting to use a shared pool for these OSet. // To have multiple OSets sharing a pool allocator, create the first OSet @@ -237,10 +237,10 @@ extern OSet* VG_(OSetGen_Create_With_Pool) ( PtrdiffT keyOff, OSetCmp_t cmp, // VG_(OSetGen_EmptyClone). extern void VG_(OSetGen_Destroy) ( OSet* os ); -extern void* VG_(OSetGen_AllocNode) ( OSet* os, SizeT elemSize ); -extern void VG_(OSetGen_FreeNode) ( OSet* os, void* elem ); +extern void* VG_(OSetGen_AllocNode) ( const OSet* os, SizeT elemSize ); +extern void VG_(OSetGen_FreeNode) ( const OSet* os, void* elem ); -extern OSet* VG_(OSetGen_EmptyClone) (OSet* os); +extern OSet* VG_(OSetGen_EmptyClone) (const OSet* os); // Creates a new empty OSet. // The new OSet will have the same characteristics as os. // If os uses a pool allocator, this pool allocator will be shared with diff --git a/include/pub_tool_sparsewa.h b/include/pub_tool_sparsewa.h index f918eb2497..f56e631c9c 100644 --- a/include/pub_tool_sparsewa.h +++ b/include/pub_tool_sparsewa.h @@ -76,7 +76,7 @@ Bool VG_(delFromSWA) ( SparseWA* swa, // mapping), and returns the associated value, if any, in *valP. For // compatibility with WordFM, 'key' is also returned in *keyP. Returned // Bool is True iff a binding for 'key' actually existed. -Bool VG_(lookupSWA) ( SparseWA* swa, +Bool VG_(lookupSWA) ( const SparseWA* swa, /*OUT*/UWord* keyP, /*OUT*/UWord* valP, UWord key ); @@ -93,7 +93,7 @@ Bool VG_(nextIterSWA)( SparseWA* swa, // How many elements are there in 'swa'? NOTE: dangerous in the // sense that this is not an O(1) operation but rather O(N), // since it involves walking the whole tree. -UWord VG_(sizeSWA) ( SparseWA* swa ); +UWord VG_(sizeSWA) ( const SparseWA* swa ); #endif // __PUB_TOOL_SPARSEWA_H diff --git a/include/pub_tool_wordfm.h b/include/pub_tool_wordfm.h index bd7e2214ba..1f1c979336 100644 --- a/include/pub_tool_wordfm.h +++ b/include/pub_tool_wordfm.h @@ -99,7 +99,7 @@ Bool VG_(delFromFM) ( WordFM* fm, /*OUT*/UWord* oldK, /*OUT*/UWord* oldV, UWord key ); // Look up in fm, assigning found key & val at spec'd addresses -Bool VG_(lookupFM) ( WordFM* fm, +Bool VG_(lookupFM) ( const WordFM* fm, /*OUT*/UWord* keyP, /*OUT*/UWord* valP, UWord key ); // Find the closest key values bracketing the given key, assuming the @@ -118,7 +118,7 @@ Bool VG_(lookupFM) ( WordFM* fm, // False is returned, and *kMinP, *vMinP, *kMaxP and *vMaxP are // undefined. Any of kMinP, vMinP, kMaxP and vMaxP may be safely // supplied as NULL. -Bool VG_(findBoundsFM)( WordFM* fm, +Bool VG_(findBoundsFM)( const WordFM* fm, /*OUT*/UWord* kMinP, /*OUT*/UWord* vMinP, /*OUT*/UWord* kMaxP, /*OUT*/UWord* vMaxP, UWord minKey, UWord minVal, @@ -128,7 +128,7 @@ Bool VG_(findBoundsFM)( WordFM* fm, // How many elements are there in fm? NOTE: dangerous in the // sense that this is not an O(1) operation but rather O(N), // since it involves walking the whole tree. -UWord VG_(sizeFM) ( WordFM* fm ); +UWord VG_(sizeFM) ( const WordFM* fm ); // set up FM for iteration void VG_(initIterFM) ( WordFM* fm ); @@ -180,23 +180,23 @@ void VG_(deleteBag) ( WordBag* ); void VG_(addToBag)( WordBag*, UWord ); /* Find out how many times the given word exists in the bag. */ -UWord VG_(elemBag) ( WordBag*, UWord ); +UWord VG_(elemBag) ( const WordBag*, UWord ); /* Delete a word from the bag. */ Bool VG_(delFromBag)( WordBag*, UWord ); /* Is the bag empty? */ -Bool VG_(isEmptyBag)( WordBag* ); +Bool VG_(isEmptyBag)( const WordBag* ); /* Does the bag have exactly one element? */ -Bool VG_(isSingletonTotalBag)( WordBag* ); +Bool VG_(isSingletonTotalBag)( const WordBag* ); /* Return an arbitrary element from the bag. */ -UWord VG_(anyElementOfBag)( WordBag* ); +UWord VG_(anyElementOfBag)( const WordBag* ); /* How many different / total elements are in the bag? */ -UWord VG_(sizeUniqueBag)( WordBag* ); /* fast */ -UWord VG_(sizeTotalBag)( WordBag* ); /* warning: slow */ +UWord VG_(sizeUniqueBag)( const WordBag* ); /* fast */ +UWord VG_(sizeTotalBag)( const WordBag* ); /* warning: slow */ /* Iterating over the elements of a bag. */ void VG_(initIterBag)( WordBag* ); diff --git a/memcheck/tests/unit_oset.c b/memcheck/tests/unit_oset.c index bf11bba4d0..6b82445a50 100644 --- a/memcheck/tests/unit_oset.c +++ b/memcheck/tests/unit_oset.c @@ -69,7 +69,7 @@ static void free_node(void* p) // case a Word), in which case the element is also the key. __attribute__((unused)) -static HChar *wordToStr(void *p) +static const HChar *wordToStr(const void *p) { static HChar buf[32]; sprintf(buf, "%ld", *(Word*)p);