From: Nicholas Nethercote Date: Sun, 14 Aug 2005 06:24:20 +0000 (+0000) Subject: Changed many, but not all, of the VgHashNode* parameters and return X-Git-Tag: svn/VALGRIND_3_1_0~614 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d07a9ad268bc0b0ce3dc1cb6fcfe8bc544bddc5;p=thirdparty%2Fvalgrind.git Changed many, but not all, of the VgHashNode* parameters and return types in m_hashtable.c to void*. This requires no changes to code already using VgHashTables, but it allows some previously-required casts to be removed. I also changed Memcheck and Massif by removing some of these now-unnecessary casts. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4404 --- diff --git a/coregrind/m_hashtable.c b/coregrind/m_hashtable.c index 7aef05dd0d..cbb8886396 100644 --- a/coregrind/m_hashtable.c +++ b/coregrind/m_hashtable.c @@ -40,7 +40,7 @@ #define CHAIN_NO(key,tbl) (((UWord)(key)) % tbl->n_chains) struct _VgHashTable { - UInt n_chains; // should be prime + UInt n_chains; // should be prime VgHashNode* chains[0]; }; @@ -71,8 +71,9 @@ Int VG_(HT_count_nodes) ( VgHashTable table ) /* Puts a new, heap allocated VgHashNode, into the VgHashTable. Prepends the node to the appropriate chain. */ -void VG_(HT_add_node) ( VgHashTable table, VgHashNode* node ) +void VG_(HT_add_node) ( VgHashTable table, void* vnode ) { + VgHashNode* node = (VgHashNode*)vnode; UInt chain = CHAIN_NO(node->key, table); node->next = table->chains[chain]; table->chains[chain] = node; @@ -81,8 +82,8 @@ void VG_(HT_add_node) ( VgHashTable table, VgHashNode* node ) /* Looks up a VgHashNode in the table. Also returns the address of the previous node's 'next' pointer which allows it to be removed from the list later without having to look it up again. */ -VgHashNode* VG_(HT_get_node) ( VgHashTable table, UWord key, - /*OUT*/VgHashNode*** next_ptr ) +void* VG_(HT_get_node) ( VgHashTable table, UWord key, + /*OUT*/VgHashNode*** next_ptr ) { VgHashNode *prev, *curr; Int chain; @@ -109,7 +110,7 @@ VgHashNode* VG_(HT_get_node) ( VgHashTable table, UWord key, } /* Looks up a VgHashNode in the table. Returns NULL if not found. */ -VgHashNode* VG_(HT_lookup) ( VgHashTable table, UWord key ) +void* VG_(HT_lookup) ( VgHashTable table, UWord key ) { VgHashNode* curr = table->chains[ CHAIN_NO(key, table) ]; @@ -123,7 +124,7 @@ VgHashNode* VG_(HT_lookup) ( VgHashTable table, UWord key ) } /* Removes a VgHashNode from the table. Returns NULL if not found. */ -VgHashNode* VG_(HT_remove) ( VgHashTable table, UWord key ) +void* VG_(HT_remove) ( VgHashTable table, UWord key ) { Int chain = CHAIN_NO(key, table); VgHashNode* curr = table->chains[chain]; @@ -173,9 +174,9 @@ VgHashNode** VG_(HT_to_array) ( VgHashTable table, /*OUT*/ UInt* n_shadows ) } /* Return the first VgHashNode satisfying the predicate p. */ -VgHashNode* VG_(HT_first_match) ( VgHashTable table, - Bool (*p) ( VgHashNode*, void* ), - void* d ) +void* VG_(HT_first_match) ( VgHashTable table, + Bool (*p) ( VgHashNode*, void* ), + void* d ) { UInt i; VgHashNode* node; diff --git a/include/pub_tool_hashtable.h b/include/pub_tool_hashtable.h index ec065f98ec..165fefdf8a 100644 --- a/include/pub_tool_hashtable.h +++ b/include/pub_tool_hashtable.h @@ -59,19 +59,19 @@ extern VgHashTable VG_(HT_construct) ( UInt n_chains ); extern Int VG_(HT_count_nodes) ( VgHashTable table ); /* Add a node to the table. */ -extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node ); +extern void VG_(HT_add_node) ( VgHashTable t, void* node ); /* Looks up a node in the hash table. Also returns the address of the previous node's `next' pointer which allows it to be removed from the list later without having to look it up again. */ -extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key, +extern void* VG_(HT_get_node) ( VgHashTable t, UWord key, /*OUT*/VgHashNode*** next_ptr ); /* Looks up a VgHashNode in the table. Returns NULL if not found. */ -extern VgHashNode* VG_(HT_lookup) ( VgHashTable table, UWord key ); +extern void* VG_(HT_lookup) ( VgHashTable table, UWord key ); /* Removes a VgHashNode from the table. Returns NULL if not found. */ -extern VgHashNode* VG_(HT_remove) ( VgHashTable table, UWord key ); +extern void* VG_(HT_remove) ( VgHashTable table, UWord key ); /* Allocates an array of pointers to all the shadow chunks of malloc'd blocks. Must be freed with VG_(free)(). */ @@ -80,9 +80,9 @@ extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows ); /* Returns first node that matches predicate `p', or NULL if none do. Extra arguments can be implicitly passed to `p' using `d' which is an opaque pointer passed to `p' each time it is called. */ -extern VgHashNode* VG_(HT_first_match) ( VgHashTable t, - Bool (*p)(VgHashNode*, void*), - void* d ); +extern void* VG_(HT_first_match) ( VgHashTable t, + Bool (*p)(VgHashNode*, void*), + void* d ); /* Applies a function f() once to each node. Again, `d' can be used to pass extra information to the function. */ diff --git a/massif/ms_main.c b/massif/ms_main.c index bff4de5398..7a278ca687 100644 --- a/massif/ms_main.c +++ b/massif/ms_main.c @@ -690,7 +690,7 @@ void* new_block ( ThreadId tid, void* p, SizeT size, SizeT align, if (0 != size) update_XCon(hc->where, size); } - VG_(HT_add_node)(malloc_list, (VgHashNode*)hc); + VG_(HT_add_node)(malloc_list, hc); n_heap_blocks++; // do a census! @@ -821,7 +821,7 @@ static void* ms_realloc ( ThreadId tid, void* p_old, SizeT new_size ) // will have removed and then re-added mc unnecessarily. But that's ok // because shrinking a block with realloc() is (presumably) much rarer // than growing it, and this way simplifies the growing case. - VG_(HT_add_node)(malloc_list, (VgHashNode*)hc); + VG_(HT_add_node)(malloc_list, hc); VGP_POPCC(VgpCliMalloc); return p_new; diff --git a/memcheck/mac_malloc_wrappers.c b/memcheck/mac_malloc_wrappers.c index de6fac134d..92a29477b3 100644 --- a/memcheck/mac_malloc_wrappers.c +++ b/memcheck/mac_malloc_wrappers.c @@ -212,8 +212,7 @@ void* MAC_(new_block) ( ThreadId tid, // Only update this stat if allocation succeeded. cmalloc_bs_mallocd += size; - VG_(HT_add_node)( table, - (VgHashNode*)create_MAC_Chunk(tid, p, size, kind) ); + VG_(HT_add_node)( table, create_MAC_Chunk(tid, p, size, kind) ); MAC_(ban_mem_heap)( p-rzB, rzB ); MAC_(new_mem_heap)( p, size, is_zeroed ); @@ -417,7 +416,7 @@ void* MAC_(realloc) ( ThreadId tid, void* p_old, SizeT new_size ) // will have removed and then re-added mc unnecessarily. But that's ok // because shrinking a block with realloc() is (presumably) much rarer // than growing it, and this way simplifies the growing case. - VG_(HT_add_node)( MAC_(malloc_list), (VgHashNode*)mc ); + VG_(HT_add_node)( MAC_(malloc_list), mc ); VGP_POPCC(VgpCliMalloc); return p_new; @@ -444,7 +443,7 @@ void MAC_(create_mempool)(Addr pool, UInt rzB, Bool is_zeroed) VG_(tool_panic)("MAC_(create_mempool): shadow area is accessible"); } - VG_(HT_add_node)( MAC_(mempool_list), (VgHashNode*)mp ); + VG_(HT_add_node)( MAC_(mempool_list), mp ); } @@ -525,7 +524,8 @@ typedef } MallocStats; -static void malloc_stats_count_chunk(VgHashNode* node, void* d) { +static void malloc_stats_count_chunk(VgHashNode* node, void* d) +{ MAC_Chunk* mc = (MAC_Chunk*)node; MallocStats *ms = (MallocStats *)d;