dovecot-2.2: lib: Changed hash_table_remove() "key not found" pa...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jun 12 09:52:56 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/5c617a5036f3
changeset: 17454:5c617a5036f3
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jun 12 12:51:34 2014 +0300
description:
lib: Changed hash_table_remove() "key not found" panic to be in a macro itself.
This makes it much easier to find out where such crashes are coming from.
Since this breaks the ABI in such a many places the ABI version number was
increased immediately..

diffstat:

 configure.ac   |   2 +-
 src/lib/hash.c |   7 ++++---
 src/lib/hash.h |  11 ++++++++---
 3 files changed, 13 insertions(+), 7 deletions(-)

diffs (72 lines):

diff -r 655c4b63035c -r 5c617a5036f3 configure.ac
--- a/configure.ac	Tue Jun 10 17:49:45 2014 +0200
+++ b/configure.ac	Thu Jun 12 12:51:34 2014 +0300
@@ -3,7 +3,7 @@
 # Be sure to update ABI version also if anything changes that might require
 # recompiling plugins. Most importantly that means if any structs are changed.
 AC_INIT([Dovecot],[2.2.13],[dovecot at dovecot.org])
-AC_DEFINE_UNQUOTED([DOVECOT_ABI_VERSION], "2.2.ABIv13($PACKAGE_VERSION)", [Dovecot ABI version])
+AC_DEFINE_UNQUOTED([DOVECOT_ABI_VERSION], "2.2.ABIv13.2($PACKAGE_VERSION)", [Dovecot ABI version])
 
 AC_CONFIG_SRCDIR([src])
 
diff -r 655c4b63035c -r 5c617a5036f3 src/lib/hash.c
--- a/src/lib/hash.c	Tue Jun 10 17:49:45 2014 +0200
+++ b/src/lib/hash.c	Thu Jun 12 12:51:34 2014 +0300
@@ -18,7 +18,7 @@
 #undef hash_table_lookup_full
 #undef hash_table_insert
 #undef hash_table_update
-#undef hash_table_remove
+#undef hash_table_try_remove
 #undef hash_table_count
 #undef hash_table_iterate_init
 #undef hash_table_iterate
@@ -326,7 +326,7 @@
         table->removed_count = 0;
 }
 
-void hash_table_remove(struct hash_table *table, const void *key)
+bool hash_table_try_remove(struct hash_table *table, const void *key)
 {
 	struct hash_node *node;
 	unsigned int hash;
@@ -335,7 +335,7 @@
 
 	node = hash_table_lookup_node(table, key, hash);
 	if (unlikely(node == NULL))
-		i_panic("key not found from hash");
+		return FALSE;
 
 	node->key = NULL;
 	table->nodes_count--;
@@ -344,6 +344,7 @@
 		table->removed_count++;
 	else if (!hash_table_resize(table, FALSE))
 		hash_table_compress(table, &table->nodes[hash % table->size]);
+	return TRUE;
 }
 
 unsigned int hash_table_count(const struct hash_table *table)
diff -r 655c4b63035c -r 5c617a5036f3 src/lib/hash.h
--- a/src/lib/hash.h	Tue Jun 10 17:49:45 2014 +0200
+++ b/src/lib/hash.h	Thu Jun 12 12:51:34 2014 +0300
@@ -110,10 +110,15 @@
 		(void *)((char *)(key) + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE((table)._key, key)), \
 		(void *)((char *)(value) + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE((table)._value, value)))
 
-void hash_table_remove(struct hash_table *table, const void *key);
+bool hash_table_try_remove(struct hash_table *table, const void *key);
+#define hash_table_try_remove(table, key) \
+	hash_table_try_remove((table)._table, \
+		(const void *)((const char *)(key) + COMPILE_ERROR_IF_TYPES2_NOT_COMPATIBLE((table)._const_key, (table)._key, key)))
 #define hash_table_remove(table, key) \
-	hash_table_remove((table)._table, \
-		(const void *)((const char *)(key) + COMPILE_ERROR_IF_TYPES2_NOT_COMPATIBLE((table)._const_key, (table)._key, key)))
+	STMT_START { \
+		if (unlikely(!hash_table_try_remove(table, key))) \
+        		i_panic("key not found from hash"); \
+	} STMT_END
 unsigned int hash_table_count(const struct hash_table *table) ATTR_PURE;
 #define hash_table_count(table) \
 	hash_table_count((table)._table)


More information about the dovecot-cvs mailing list