From: Florian Krohm Date: Sat, 18 Oct 2014 10:58:05 +0000 (+0000) Subject: Change the definition of VgHashTable to not have pointer type. X-Git-Tag: svn/VALGRIND_3_11_0~909 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5e2bdbddcd0e1263f6a6cc160a57e01c9aeca90;p=thirdparty%2Fvalgrind.git Change the definition of VgHashTable to not have pointer type. This is (a) consistent with how the other containers are defined and, more importantly, (b) allows the constification of the hash table API. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14639 --- diff --git a/coregrind/m_debuginfo/readdwarf3.c b/coregrind/m_debuginfo/readdwarf3.c index db924d72f3..89c7e2fff0 100644 --- a/coregrind/m_debuginfo/readdwarf3.c +++ b/coregrind/m_debuginfo/readdwarf3.c @@ -467,7 +467,7 @@ typedef /* --- Needed so we can add stuff to the string table. --- */ struct _DebugInfo* di; /* --- a hash table of g_abbv (i.e. parsed abbreviations) --- */ - VgHashTable ht_abbvs; + VgHashTable *ht_abbvs; /* True if this came from .debug_types; otherwise it came from .debug_info. */ @@ -480,7 +480,7 @@ typedef /* Signatured type hash; computed once and then shared by all CUs. */ - VgHashTable signature_types; + VgHashTable *signature_types; /* True if this came from alternate .debug_info; otherwise it came from normal .debug_info or .debug_types. */ @@ -1081,7 +1081,7 @@ typedef D3SignatureType; /* Record a signatured type in the hash table. */ -static void record_signatured_type ( VgHashTable tab, +static void record_signatured_type ( VgHashTable *tab, ULong type_signature, UWord die ) { @@ -1096,7 +1096,7 @@ static void record_signatured_type ( VgHashTable tab, /* Given a type signature hash table and a type signature, return the cooked DIE offset of the type. If the type cannot be found, call BARF. */ -static UWord lookup_signatured_type ( VgHashTable tab, +static UWord lookup_signatured_type ( const VgHashTable *tab, ULong type_signature, void (*barf)( const HChar* ) __attribute__((noreturn)) ) { @@ -4439,7 +4439,7 @@ void new_dwarf3_reader_wrk ( Bool td3 = di->trace_symtab; XArray* /* of TempVar* */ dioff_lookup_tab; Int pass; - VgHashTable signature_types = NULL; + VgHashTable *signature_types = NULL; /* Display/trace various information, if requested. */ if (TD3) { diff --git a/coregrind/m_deduppoolalloc.c b/coregrind/m_deduppoolalloc.c index 53d68535e7..dd69c7ffd5 100644 --- a/coregrind/m_deduppoolalloc.c +++ b/coregrind/m_deduppoolalloc.c @@ -52,7 +52,7 @@ struct _DedupPoolAlloc { /* hash table of pool elements, used to dedup. If NULL, it means the DedupPoolAlloc is frozen. */ - VgHashTable ht_elements; + VgHashTable *ht_elements; /* Hash table nodes of pool_elements are allocated with a pool, to decrease memory overhead during insertion in the DedupPoolAlloc. */ diff --git a/coregrind/m_gdbserver/m_gdbserver.c b/coregrind/m_gdbserver/m_gdbserver.c index 3ce18606aa..6e10593fbf 100644 --- a/coregrind/m_gdbserver/m_gdbserver.c +++ b/coregrind/m_gdbserver/m_gdbserver.c @@ -194,7 +194,7 @@ typedef Note for ARM: addr in GS_Address is the value without the thumb bit set. */ -static VgHashTable gs_addresses = NULL; +static VgHashTable *gs_addresses = NULL; // Transform addr in the form stored in the list of addresses. // For the ARM architecture, we store it with the thumb bit set to 0. diff --git a/coregrind/m_hashtable.c b/coregrind/m_hashtable.c index 5abea0a572..3e52235862 100644 --- a/coregrind/m_hashtable.c +++ b/coregrind/m_hashtable.c @@ -54,7 +54,7 @@ struct _VgHashTable { #define N_HASH_PRIMES 20 -static SizeT primes[N_HASH_PRIMES] = { +static const SizeT primes[N_HASH_PRIMES] = { 769UL, 1543UL, 3079UL, 6151UL, 12289UL, 24593UL, 49157UL, 98317UL, 196613UL, 393241UL, 786433UL, 1572869UL, @@ -66,12 +66,12 @@ static SizeT primes[N_HASH_PRIMES] = { /*--- Functions ---*/ /*--------------------------------------------------------------------*/ -VgHashTable VG_(HT_construct) ( const HChar* name ) +VgHashTable *VG_(HT_construct) ( const HChar* name ) { /* Initialises to zero, ie. all entries NULL */ SizeT n_chains = primes[0]; SizeT sz = n_chains * sizeof(VgHashNode*); - VgHashTable table = VG_(calloc)("hashtable.Hc.1", + VgHashTable *table = VG_(calloc)("hashtable.Hc.1", 1, sizeof(struct _VgHashTable)); table->chains = VG_(calloc)("hashtable.Hc.2", 1, sz); table->n_chains = n_chains; @@ -82,12 +82,12 @@ VgHashTable VG_(HT_construct) ( const HChar* name ) return table; } -Int VG_(HT_count_nodes) ( VgHashTable table ) +Int VG_(HT_count_nodes) ( const VgHashTable *table ) { return table->n_elements; } -static void resize ( VgHashTable table ) +static void resize ( VgHashTable *table ) { Int i; SizeT sz; @@ -141,7 +141,7 @@ static void resize ( VgHashTable table ) /* Puts a new, heap allocated VgHashNode, into the VgHashTable. Prepends the node to the appropriate chain. No duplicate key detection is done. */ -void VG_(HT_add_node) ( VgHashTable table, void* vnode ) +void VG_(HT_add_node) ( VgHashTable *table, void* vnode ) { VgHashNode* node = (VgHashNode*)vnode; UWord chain = CHAIN_NO(node->key, table); @@ -157,7 +157,7 @@ void VG_(HT_add_node) ( VgHashTable table, void* vnode ) } /* Looks up a VgHashNode by key in the table. Returns NULL if not found. */ -void* VG_(HT_lookup) ( VgHashTable table, UWord key ) +void* VG_(HT_lookup) ( const VgHashTable *table, UWord key ) { VgHashNode* curr = table->chains[ CHAIN_NO(key, table) ]; @@ -172,9 +172,10 @@ void* VG_(HT_lookup) ( VgHashTable table, UWord key ) /* Looks up a VgHashNode by node in the table. Returns NULL if not found. GEN!!! marks the lines that differs from VG_(HT_lookup). */ -void* VG_(HT_gen_lookup) ( VgHashTable table, void* node, HT_Cmp_t cmp ) +void* VG_(HT_gen_lookup) ( const VgHashTable *table, const void* node, + HT_Cmp_t cmp ) { - VgHashNode* hnode = (VgHashNode*) node; // GEN!!! + const VgHashNode* hnode = node; // GEN!!! VgHashNode* curr = table->chains[ CHAIN_NO(hnode->key, table) ]; // GEN!!! while (curr) { @@ -187,7 +188,7 @@ void* VG_(HT_gen_lookup) ( VgHashTable table, void* node, HT_Cmp_t cmp ) } /* Removes a VgHashNode from the table. Returns NULL if not found. */ -void* VG_(HT_remove) ( VgHashTable table, UWord key ) +void* VG_(HT_remove) ( VgHashTable *table, UWord key ) { UWord chain = CHAIN_NO(key, table); VgHashNode* curr = table->chains[chain]; @@ -210,9 +211,9 @@ void* VG_(HT_remove) ( VgHashTable table, UWord key ) /* Removes a VgHashNode by node from the table. Returns NULL if not found. GEN!!! marks the lines that differs from VG_(HT_remove). */ -void* VG_(HT_gen_remove) ( VgHashTable table, void* node, HT_Cmp_t cmp ) +void* VG_(HT_gen_remove) ( VgHashTable *table, const void* node, HT_Cmp_t cmp ) { - VgHashNode* hnode = (VgHashNode*) node; // GEN!!! + const VgHashNode* hnode = node; // GEN!!! UWord chain = CHAIN_NO(hnode->key, table); // GEN!!! VgHashNode* curr = table->chains[chain]; VgHashNode** prev_next_ptr = &(table->chains[chain]); @@ -232,7 +233,7 @@ void* VG_(HT_gen_remove) ( VgHashTable table, void* node, HT_Cmp_t cmp ) return NULL; } -void VG_(HT_print_stats) ( VgHashTable table, HT_Cmp_t cmp ) +void VG_(HT_print_stats) ( const VgHashTable *table, HT_Cmp_t cmp ) { #define MAXOCCUR 20 UInt elt_occurences[MAXOCCUR+1]; @@ -328,7 +329,7 @@ void VG_(HT_print_stats) ( VgHashTable table, HT_Cmp_t cmp ) elements into it, then returns both the array and the size of it. The array must be freed with VG_(free). */ -VgHashNode** VG_(HT_to_array) ( VgHashTable table, /*OUT*/ UInt* n_elems ) +VgHashNode** VG_(HT_to_array) (const VgHashTable *table, /*OUT*/ UInt* n_elems) { UInt i, j; VgHashNode** arr; @@ -351,7 +352,7 @@ VgHashNode** VG_(HT_to_array) ( VgHashTable table, /*OUT*/ UInt* n_elems ) return arr; } -void VG_(HT_ResetIter)(VgHashTable table) +void VG_(HT_ResetIter)(VgHashTable *table) { vg_assert(table); table->iterNode = NULL; @@ -359,7 +360,7 @@ void VG_(HT_ResetIter)(VgHashTable table) table->iterOK = True; } -void* VG_(HT_Next)(VgHashTable table) +void* VG_(HT_Next)(VgHashTable *table) { Int i; vg_assert(table); @@ -383,7 +384,7 @@ void* VG_(HT_Next)(VgHashTable table) return NULL; } -void VG_(HT_destruct)(VgHashTable table, void(*freenode_fn)(void*)) +void VG_(HT_destruct)(VgHashTable *table, void(*freenode_fn)(void*)) { UInt i; VgHashNode *node, *node_next; diff --git a/drd/drd_malloc_wrappers.c b/drd/drd_malloc_wrappers.c index 0f9896467e..369936de58 100644 --- a/drd/drd_malloc_wrappers.c +++ b/drd/drd_malloc_wrappers.c @@ -61,7 +61,7 @@ static SizeT s_cmalloc_n_mallocs = 0; static SizeT s_cmalloc_n_frees = 0; static SizeT s_cmalloc_bs_mallocd = 0; /* Record malloc'd blocks. */ -static VgHashTable s_malloc_list = NULL; +static VgHashTable *s_malloc_list = NULL; /* Function definitions. */ diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c index d1b72d0d0e..3f130743cc 100644 --- a/helgrind/hg_main.c +++ b/helgrind/hg_main.c @@ -3974,7 +3974,7 @@ typedef /* A hash table of MallocMetas, used to track malloc'd blocks (obviously). */ -static VgHashTable hg_mallocmeta_table = NULL; +static VgHashTable *hg_mallocmeta_table = NULL; /* MallocMeta are small elements. We use a pool to avoid the overhead of malloc for each MallocMeta. */ diff --git a/include/pub_tool_hashtable.h b/include/pub_tool_hashtable.h index 21dd0b234a..b105ac4043 100644 --- a/include/pub_tool_hashtable.h +++ b/include/pub_tool_hashtable.h @@ -49,28 +49,28 @@ typedef } VgHashNode; -typedef struct _VgHashTable * VgHashTable; +typedef struct _VgHashTable VgHashTable; /* Make a new table. Allocates the memory with VG_(calloc)(), so can be freed with VG_(free)(). The table starts small but will periodically be expanded. This is transparent to the users of this module. The function never returns NULL. */ -extern VgHashTable VG_(HT_construct) ( const HChar* name ); +extern VgHashTable *VG_(HT_construct) ( const HChar* name ); /* Count the number of nodes in a table. */ -extern Int VG_(HT_count_nodes) ( VgHashTable table ); +extern Int VG_(HT_count_nodes) ( const VgHashTable *table ); /* Add a node to the table. Duplicate keys are permitted. */ -extern void VG_(HT_add_node) ( VgHashTable t, void* node ); +extern void VG_(HT_add_node) ( VgHashTable *t, void* node ); /* Looks up a VgHashNode by key in the table. * Returns NULL if not found. If entries * with duplicate keys are present, the most recently-added of the dups will * be returned, but it's probably better to avoid dups altogether. */ -extern void* VG_(HT_lookup) ( VgHashTable table, UWord key ); +extern void* VG_(HT_lookup) ( const VgHashTable *table, UWord key ); /* Removes a VgHashNode by key from the table. Returns NULL if not found. */ -extern void* VG_(HT_remove) ( VgHashTable table, UWord key ); +extern void* VG_(HT_remove) ( VgHashTable *table, UWord key ); typedef Word (*HT_Cmp_t) ( const void* node1, const void* node2 ); @@ -85,22 +85,25 @@ typedef Word (*HT_Cmp_t) ( const void* node1, const void* node2 ); between components, either the node memory should be fully initialised (e.g. allocated using VG_(calloc)) or each component should be compared individually. */ -extern void* VG_(HT_gen_lookup) ( VgHashTable table, void* node, HT_Cmp_t cmp ); -extern void* VG_(HT_gen_remove) ( VgHashTable table, void* node, HT_Cmp_t cmp ); +extern void* VG_(HT_gen_lookup) ( const VgHashTable *table, const void* node, + HT_Cmp_t cmp ); +extern void* VG_(HT_gen_remove) ( VgHashTable *table, const void* node, + HT_Cmp_t cmp ); /* Output detailed usage/collision statistics. cmp will be used to verify if 2 elements with the same key are equal. Use NULL cmp if the hash table elements are only to be compared by key. */ -extern void VG_(HT_print_stats) ( VgHashTable table, HT_Cmp_t cmp ); +extern void VG_(HT_print_stats) ( const VgHashTable *table, HT_Cmp_t cmp ); /* Allocates a suitably-sized array, copies pointers to all the hashtable elements into it, then returns both the array and the size of it. The array must be freed with VG_(free). If the hashtable is empty, the function returns NULL and assigns *nelems = 0. */ -extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_elems ); +extern VgHashNode** VG_(HT_to_array) ( const VgHashTable *table, + /*OUT*/ UInt* n_elems ); /* Reset the table's iterator to point to the first element. */ -extern void VG_(HT_ResetIter) ( VgHashTable table ); +extern void VG_(HT_ResetIter) ( VgHashTable *table ); /* Return the element pointed to by the iterator and move on to the next one. Returns NULL if the last one has been passed, or if @@ -113,11 +116,11 @@ extern void VG_(HT_ResetIter) ( VgHashTable table ); Since resizing only happens as a result of calling HT_add_node, disallowing HT_add_node during iteration should give the required assurance. */ -extern void* VG_(HT_Next) ( VgHashTable table ); +extern void* VG_(HT_Next) ( VgHashTable *table ); /* Destroy a table and deallocates the memory used by the nodes using freenode_fn.*/ -extern void VG_(HT_destruct) ( VgHashTable t, void(*freenode_fn)(void*) ); +extern void VG_(HT_destruct) ( VgHashTable *table, void(*freenode_fn)(void*) ); #endif // __PUB_TOOL_HASHTABLE_H diff --git a/massif/ms_main.c b/massif/ms_main.c index 7d78b5f092..da58bb665c 100644 --- a/massif/ms_main.c +++ b/massif/ms_main.c @@ -1485,7 +1485,7 @@ typedef } HP_Chunk; -static VgHashTable malloc_list = NULL; // HP_Chunks +static VgHashTable *malloc_list = NULL; // HP_Chunks static void update_alloc_stats(SSizeT szB_delta) { diff --git a/memcheck/mc_include.h b/memcheck/mc_include.h index 26ad25e1fd..51a36c2dc7 100644 --- a/memcheck/mc_include.h +++ b/memcheck/mc_include.h @@ -93,7 +93,7 @@ typedef Addr pool; // pool identifier SizeT rzB; // pool red-zone size Bool is_zeroed; // allocations from this pool are zeroed - VgHashTable chunks; // chunks associated with this pool + VgHashTable *chunks; // chunks associated with this pool } MC_Mempool; @@ -101,7 +101,7 @@ typedef void* MC_(new_block) ( ThreadId tid, Addr p, SizeT size, SizeT align, Bool is_zeroed, MC_AllocKind kind, - VgHashTable table); + VgHashTable *table); void MC_(handle_free) ( ThreadId tid, Addr p, UInt rzB, MC_AllocKind kind ); @@ -127,10 +127,10 @@ extern PoolAlloc* MC_(chunk_poolalloc); VgHashTable, because VgHashTable allows duplicate keys without complaint. This can occur if a user marks a malloc() block as also a custom block with MALLOCLIKE_BLOCK. */ -extern VgHashTable MC_(malloc_list); +extern VgHashTable *MC_(malloc_list); /* For tracking memory pools. */ -extern VgHashTable MC_(mempool_list); +extern VgHashTable *MC_(mempool_list); /* Shadow memory functions */ Bool MC_(check_mem_is_noaccess)( Addr a, SizeT len, Addr* bad_addr ); diff --git a/memcheck/mc_malloc_wrappers.c b/memcheck/mc_malloc_wrappers.c index d88890ba7b..630c9c7e15 100644 --- a/memcheck/mc_malloc_wrappers.c +++ b/memcheck/mc_malloc_wrappers.c @@ -66,11 +66,11 @@ static ULong cmalloc_bs_mallocd = 0; SizeT MC_(Malloc_Redzone_SzB) = -10000000; // If used before set, should BOMB /* Record malloc'd blocks. */ -VgHashTable MC_(malloc_list) = NULL; +VgHashTable *MC_(malloc_list) = NULL; /* Memory pools: a hash table of MC_Mempools. Search key is MC_Mempool::pool. */ -VgHashTable MC_(mempool_list) = NULL; +VgHashTable *MC_(mempool_list) = NULL; /* Pool allocator for MC_Chunk. */ PoolAlloc *MC_(chunk_poolalloc) = NULL; @@ -224,7 +224,7 @@ void delete_MC_Chunk (MC_Chunk* mc) } // True if mc is in the given block list. -static Bool in_block_list (VgHashTable block_list, MC_Chunk* mc) +static Bool in_block_list (const VgHashTable *block_list, MC_Chunk* mc) { MC_Chunk* found_mc = VG_(HT_lookup) ( block_list, (UWord)mc->data ); if (found_mc) { @@ -338,7 +338,7 @@ UInt MC_(n_where_pointers) (void) /* Allocate memory and note change in memory available */ void* MC_(new_block) ( ThreadId tid, Addr p, SizeT szB, SizeT alignB, - Bool is_zeroed, MC_AllocKind kind, VgHashTable table) + Bool is_zeroed, MC_AllocKind kind, VgHashTable *table) { MC_Chunk* mc;