From bfbd52709bdd01615224688d1c2831225a4bbbee Mon Sep 17 00:00:00 2001 From: theraven Date: Fri, 12 Mar 2010 18:53:27 +0000 Subject: [PATCH] Fixed off-by-one error in hash table enumerator, which was causing one class to fail to be resolved. --- GNUmakefile | 2 +- hash_table.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/GNUmakefile b/GNUmakefile index dce44c9..5d5015e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -66,7 +66,7 @@ libobjc_CPPFLAGS += -D__OBJC_RUNTIME_INTERNAL__=1 -D_XOPEN_SOURCE=500 # useful on compilers that support C99 (currently only clang), so there is no # benefit from supporting platforms with no C99 compiler. libobjc_CFLAGS += -Werror -std=c99 -g -march=native -fexceptions #-fno-inline -libobjc_OBJCFLAGS += -g -std=c99 +libobjc_OBJCFLAGS += -g -std=c99 -march=native libobjc_LDFLAGS += -g -ltoydispatch libobjc_LIB_DIRS += -L toydispatch/obj diff --git a/hash_table.h b/hash_table.h index 7c14f6c..c1dbeeb 100644 --- a/hash_table.h +++ b/hash_table.h @@ -175,15 +175,19 @@ static int PREFIX(_table_resize)(PREFIX(_table) *table) // Now we make the original table structure point to the new (empty) array. table->table = newArray; table->table_size *= 2; + // The table currently has no entries; the copy has them all. + table->table_used = 0; // Finally, copy everything into the new table // Note: we should really do this in a background thread. At this stage, // we can do the updates safely without worrying about read contention. + int copied = 0; for (uint32_t i=0 ; itable_size ; i++) { MAP_TABLE_VALUE_TYPE value = copy->table[i].value; if (!MAP_TABLE_VALUE_NULL(value)) { + copied++; PREFIX(_insert)(table, value); } } @@ -318,6 +322,7 @@ static int PREFIX(_insert)(PREFIX(_table) *table, MAP_UNLOCK(); return PREFIX(_insert)(table, value); } + fprintf(stderr, "Insert failed\n"); return 0; } @@ -446,6 +451,7 @@ PREFIX(_next)(PREFIX(_table) *table, // enumerating MAP_LOCK(); (*state)->table = table; + (*state)->index = -1; __sync_fetch_and_add(&table->enumerator_count, 1); MAP_UNLOCK(); } @@ -465,6 +471,7 @@ PREFIX(_next)(PREFIX(_table) *table, { if (!MAP_TABLE_VALUE_NULL((*state)->table->table[(*state)->index].value)) { + (*state)->seen++; #ifdef MAP_TABLE_ACCESS_BY_REFERENCE return &(*state)->table->table[(*state)->index].value; #else