]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
whoops
authorNicholas Nethercote <njn@valgrind.org>
Sun, 3 Jul 2005 17:10:04 +0000 (17:10 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Sun, 3 Jul 2005 17:10:04 +0000 (17:10 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4099

Makefile.am
coregrind/m_hashtable.c

index 7db6476fe5d33db742c168a2fd4a092199d354d7..d9e42f89e462fb0b8b664a1193e2b144172e12eb 100644 (file)
@@ -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
index fd8ace04d557c8e0576ffdd38d564ce40da01f7d..4e6a59924b53db28a95c3f89731c3b09b2aa9bc0 100644 (file)
 
 /* 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);
       }
    }