From: Nicholas Nethercote Date: Sun, 3 Jul 2005 17:10:04 +0000 (+0000) Subject: whoops X-Git-Tag: svn/VALGRIND_3_0_0~219 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd80a229b4b504f84ead46043575757d2a7202a1;p=thirdparty%2Fvalgrind.git whoops git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4099 --- diff --git a/Makefile.am b/Makefile.am index 7db6476fe5..d9e42f89e4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,7 +20,7 @@ SUBDIRS = include coregrind . tests auxprogs $(TOOLS) helgrind docs DIST_SUBDIRS = $(SUBDIRS) addrcheck SUPP_FILES = \ - glibc-2.1.supp glibc-2.2.supp glibc-2.3.supp glibc-2.4.supp \ + glibc-2.2.supp glibc-2.3.supp glibc-2.4.supp \ xfree-3.supp xfree-4.supp dist_val_DATA = $(SUPP_FILES) default.supp diff --git a/coregrind/m_hashtable.c b/coregrind/m_hashtable.c index fd8ace04d5..4e6a59924b 100644 --- a/coregrind/m_hashtable.c +++ b/coregrind/m_hashtable.c @@ -39,18 +39,28 @@ /* Holds malloc'd but not freed blocks. Static, so zero-inited by default. */ -#define VG_N_CHAINS 80021 /*4999*/ /* a prime number */ +//#define VG_N_CHAINS 80021 /*4999*/ /* a prime number */ -#define VG_CHAIN_NO(aa) (((UWord)(aa)) % VG_N_CHAINS) +#define CHAIN_NO(key,tbl) (((UWord)(key)) % tbl->n_chains) + +struct { + UInt n_chains; // should be prime + VgHashNode* chains[0]; +} +_VgHashTable; + +typedef (struct _VgHashTable *) VgHashTable; /*--------------------------------------------------------------------*/ /*--- Functions ---*/ /*--------------------------------------------------------------------*/ -VgHashTable VG_(HT_construct)(void) +VgHashTable VG_(HT_construct)(UInt n_chains) { /* Initialises to zero, ie. all entries NULL */ - return VG_(calloc)(VG_N_CHAINS, sizeof(VgHashNode*)); + VgHashTable* table = + VG_(calloc)(sizeof(struct _VgHashTable) + n_chains*sizeof(VgHashNode*)); + table->n_chains = n_chains; } Int VG_(HT_count_nodes) ( VgHashTable table ) @@ -59,8 +69,8 @@ Int VG_(HT_count_nodes) ( VgHashTable table ) UInt chain; Int n = 0; - for (chain = 0; chain < VG_N_CHAINS; chain++) - for (node = table[chain]; node != NULL; node = node->next) + for (chain = 0; chain < table->n_chains; chain++) + for (node = table->chains[chain]; node != NULL; node = node->next) n++; return n; } @@ -68,8 +78,8 @@ Int VG_(HT_count_nodes) ( VgHashTable table ) /* Puts a new, heap allocated VgHashNode, into the malloclist. */ void VG_(HT_add_node) ( VgHashTable table, VgHashNode* node ) { - UInt chain = VG_CHAIN_NO(node->key); - node->next = table[chain]; + UInt chain = CHAIN_NO(node->key); + node->next = table->chains[chain]; table[chain] = node; } @@ -77,15 +87,15 @@ void VG_(HT_add_node) ( VgHashTable table, VgHashNode* node ) 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 ) + /*OUT*/VgHashNode*** next_ptr ) { VgHashNode *prev, *curr; Int chain; - chain = VG_CHAIN_NO(key); + chain = CHAIN_NO(key); prev = NULL; - curr = table[chain]; + curr = table->chains[chain]; while (True) { if (curr == NULL) break; @@ -96,9 +106,9 @@ VgHashNode* VG_(HT_get_node) ( VgHashTable table, UWord key, } if (NULL == prev) - *next_ptr = & table[chain]; + *next_ptr = & (table->chain[chain]); else - *next_ptr = & prev->next; + *next_ptr = & (prev->next); return curr; } @@ -114,8 +124,8 @@ VgHashNode** VG_(HT_to_array) ( VgHashTable table, /*OUT*/ UInt* n_shadows ) VgHashNode* node; *n_shadows = 0; - for (i = 0; i < VG_N_CHAINS; i++) { - for (node = table[i]; node != NULL; node = node->next) { + for (i = 0; i < table->n_chains; i++) { + for (node = table->chains[i]; node != NULL; node = node->next) { (*n_shadows)++; } } @@ -125,8 +135,8 @@ VgHashNode** VG_(HT_to_array) ( VgHashTable table, /*OUT*/ UInt* n_shadows ) arr = VG_(malloc)( *n_shadows * sizeof(VgHashNode*) ); j = 0; - for (i = 0; i < VG_N_CHAINS; i++) { - for (node = table[i]; node != NULL; node = node->next) { + for (i = 0; i < table->n_chains; i++) { + for (node = table->chains[i]; node != NULL; node = node->next) { arr[j++] = node; } } @@ -143,8 +153,8 @@ VgHashNode* VG_(HT_first_match) ( VgHashTable table, UInt i; VgHashNode* node; - for (i = 0; i < VG_N_CHAINS; i++) - for (node = table[i]; node != NULL; node = node->next) + for (i = 0; i < table->n_chains; i++) + for (node = table->chains[i]; node != NULL; node = node->next) if ( p(node, d) ) return node; @@ -158,8 +168,8 @@ void VG_(HT_apply_to_all_nodes)( VgHashTable table, UInt i; VgHashNode* node; - for (i = 0; i < VG_N_CHAINS; i++) { - for (node = table[i]; node != NULL; node = node->next) { + for (i = 0; i < table->n_chains; i++) { + for (node = table->chains[i]; node != NULL; node = node->next) { f(node, d); } } @@ -170,8 +180,8 @@ void VG_(HT_destruct)(VgHashTable table) UInt i; VgHashNode* node; - for (i = 0; i < VG_N_CHAINS; i++) { - for (node = table[i]; node != NULL; node = node->next) { + for (i = 0; i < table->n_chains; i++) { + for (node = table->chains[i]; node != NULL; node = node->next) { VG_(free)(node); } }