dovecot-2.2: Reverted "support for non-pointers" part of the has...

dovecot at dovecot.org dovecot at dovecot.org
Mon Aug 20 09:47:47 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/96fd2c3bf932
changeset: 14923:96fd2c3bf932
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Aug 20 09:47:28 2012 +0300
description:
Reverted "support for non-pointers" part of the hash table API changes.
Originally I wrote it using clang, which didn't give as many warnings as gcc
did. I guess this way is safer anyway..

diffstat:

 src/anvil/connect-limit.c                          |  35 +++++++------
 src/auth/auth-request-handler.c                    |  24 ++++-----
 src/auth/db-checkpassword.c                        |  18 +++---
 src/auth/db-ldap.c                                 |   2 +-
 src/auth/db-passwd-file.c                          |   2 +-
 src/director/director-test.c                       |  13 ++--
 src/director/user-directory.c                      |  10 +-
 src/doveadm/doveadm-director.c                     |   9 +-
 src/doveadm/doveadm-kick.c                         |  17 ++---
 src/doveadm/doveadm-log.c                          |  14 ++---
 src/doveadm/doveadm-mail-server.c                  |   9 +-
 src/doveadm/doveadm-stats.c                        |   2 +-
 src/doveadm/doveadm-who.c                          |   6 +-
 src/doveadm/dsync/dsync-mailbox-export.c           |  56 ++++++++++-----------
 src/doveadm/dsync/dsync-mailbox-import.c           |  29 ++++++-----
 src/doveadm/dsync/dsync-transaction-log-scan.c     |   7 +-
 src/doveadm/dsync/dsync-transaction-log-scan.h     |   2 +-
 src/imap/imap-client.c                             |   2 +-
 src/lib-auth/auth-server-connection.c              |  13 ++--
 src/lib-auth/auth-server-connection.h              |   3 +-
 src/lib-dict/dict-file.c                           |   8 +-
 src/lib-index/mail-cache-fields.c                  |  22 ++++----
 src/lib-index/mail-cache-private.h                 |   2 +-
 src/lib-index/mail-index-private.h                 |   2 +-
 src/lib-index/mail-index.c                         |   6 +-
 src/lib-lda/duplicate.c                            |   2 +-
 src/lib-master/master-auth.c                       |  16 +++---
 src/lib-master/master-login-auth.c                 |  10 +-
 src/lib-settings/settings-parser.c                 |   7 +-
 src/lib-storage/index/dbox-multi/mdbox-purge.c     |  15 +++-
 src/lib-storage/index/index-thread-finish.c        |   4 +-
 src/lib-storage/index/maildir/maildir-keywords.c   |  18 +++---
 src/lib-storage/list/mailbox-list-index-sync.c     |   9 ++-
 src/lib-storage/list/mailbox-list-index.c          |   9 +-
 src/lib-storage/list/mailbox-list-index.h          |   8 +-
 src/lib/child-wait.c                               |  24 +++++----
 src/lib/hash.c                                     |   6 +-
 src/lib/hash.h                                     |  26 +++------
 src/log/log-connection.c                           |  20 ++++---
 src/login-common/ssl-proxy-openssl.c               |   2 +-
 src/master/service-monitor.c                       |   4 +-
 src/master/service-process.c                       |   4 +-
 src/master/service.c                               |   7 +-
 src/master/service.h                               |   2 +-
 src/plugins/acl/acl-cache.c                        |  14 +++--
 src/plugins/expire/doveadm-expire.c                |  14 +++--
 src/plugins/fts-lucene/lucene-wrapper.cc           |   2 +-
 src/plugins/fts/fts-expunge-log.c                  |   2 +-
 src/pop3/pop3-commands.c                           |  14 ++---
 src/replication/aggregator/replicator-connection.c |  10 +-
 50 files changed, 282 insertions(+), 280 deletions(-)

diffs (truncated from 1920 to 300 lines):

diff -r edb1d5babfcd -r 96fd2c3bf932 src/anvil/connect-limit.c
--- a/src/anvil/connect-limit.c	Mon Aug 20 08:31:00 2012 +0300
+++ b/src/anvil/connect-limit.c	Mon Aug 20 09:47:28 2012 +0300
@@ -15,8 +15,8 @@
 };
 
 struct connect_limit {
-	/* ident => refcount */
-	HASH_TABLE(char *, unsigned int) ident_hash;
+	/* ident => unsigned int refcount */
+	HASH_TABLE(char *, void *) ident_hash;
 	/* struct ident_pid => struct ident_pid */
 	HASH_TABLE(struct ident_pid *, struct ident_pid *) ident_pid_hash;
 };
@@ -60,24 +60,26 @@
 unsigned int connect_limit_lookup(struct connect_limit *limit,
 				  const char *ident)
 {
-	return hash_table_lookup(limit->ident_hash, ident);
+	void *value;
+
+	value = hash_table_lookup(limit->ident_hash, ident);
+	return POINTER_CAST_TO(value, unsigned int);
 }
 
 void connect_limit_connect(struct connect_limit *limit, pid_t pid,
 			   const char *ident)
 {
 	struct ident_pid *i, lookup_i;
-	void *orig_key, *orig_value;
 	char *key;
-	unsigned int value;
+	void *value;
 
 	if (!hash_table_lookup_full(limit->ident_hash, ident,
-				    &orig_key, &orig_value)) {
+				    &key, &value)) {
 		key = i_strdup(ident);
-		hash_table_insert(limit->ident_hash, key, 1U);
+		value = POINTER_CAST(1);
+		hash_table_insert(limit->ident_hash, key, value);
 	} else {
-		key = orig_key;
-		value = POINTER_CAST_TO(orig_value, unsigned int) + 1;
+		value = POINTER_CAST(POINTER_CAST_TO(value, unsigned int) + 1);
 		hash_table_update(limit->ident_hash, key, value);
 	}
 
@@ -98,18 +100,17 @@
 static void
 connect_limit_ident_hash_unref(struct connect_limit *limit, const char *ident)
 {
-	void *orig_key, *orig_value;
 	char *key;
+	void *value;
 	unsigned int new_refcount;
 
-	if (!hash_table_lookup_full(limit->ident_hash, ident,
-				    &orig_key, &orig_value))
+	if (!hash_table_lookup_full(limit->ident_hash, ident, &key, &value))
 		i_panic("connect limit hash tables are inconsistent");
 
-	key = orig_key;
-	new_refcount = POINTER_CAST_TO(orig_value, unsigned int) - 1;
+	new_refcount = POINTER_CAST_TO(value, unsigned int) - 1;
 	if (new_refcount > 0) {
-		hash_table_update(limit->ident_hash, key, new_refcount);
+		value = POINTER_CAST(new_refcount);
+		hash_table_update(limit->ident_hash, key, value);
 	} else {
 		hash_table_remove(limit->ident_hash, key);
 		i_free(key);
@@ -147,7 +148,7 @@
 	/* this should happen rarely (or never), so this slow implementation
 	   should be fine. */
 	iter = hash_table_iterate_init(limit->ident_pid_hash);
-	while (hash_table_iterate_t(iter, limit->ident_pid_hash, &i, &value)) {
+	while (hash_table_iterate(iter, limit->ident_pid_hash, &i, &value)) {
 		if (i->pid == pid) {
 			hash_table_remove(limit->ident_pid_hash, i);
 			for (; i->refcount > 0; i->refcount--)
@@ -165,7 +166,7 @@
 	string_t *str = t_str_new(256);
 
 	iter = hash_table_iterate_init(limit->ident_pid_hash);
-	while (hash_table_iterate_t(iter, limit->ident_pid_hash, &i, &value)) {
+	while (hash_table_iterate(iter, limit->ident_pid_hash, &i, &value)) {
 		str_truncate(str, 0);
 		str_tabescape_write(str, i->ident);
 		str_printfa(str, "\t%ld\t%u\n", (long)i->pid, i->refcount);
diff -r edb1d5babfcd -r 96fd2c3bf932 src/auth/auth-request-handler.c
--- a/src/auth/auth-request-handler.c	Mon Aug 20 08:31:00 2012 +0300
+++ b/src/auth/auth-request-handler.c	Mon Aug 20 09:47:28 2012 +0300
@@ -21,7 +21,7 @@
 struct auth_request_handler {
 	int refcount;
 	pool_t pool;
-	HASH_TABLE(unsigned int, struct auth_request *) requests;
+	HASH_TABLE(void *, struct auth_request *) requests;
 
         unsigned int connect_uid, client_pid;
 
@@ -68,19 +68,17 @@
 void auth_request_handler_abort_requests(struct auth_request_handler *handler)
 {
 	struct hash_iterate_context *iter;
-	void *key, *value;
+	void *key;
+	struct auth_request *auth_request;
 
 	iter = hash_table_iterate_init(handler->requests);
-	while (hash_table_iterate(iter, &key, &value)) {
-		unsigned int id = POINTER_CAST_TO(key, unsigned int);
-		struct auth_request *auth_request = value;
-
+	while (hash_table_iterate(iter, handler->requests, &key, &auth_request)) {
 		switch (auth_request->state) {
 		case AUTH_REQUEST_STATE_NEW:
 		case AUTH_REQUEST_STATE_MECH_CONTINUE:
 		case AUTH_REQUEST_STATE_FINISHED:
 			auth_request_unref(&auth_request);
-			hash_table_remove(handler->requests, id);
+			hash_table_remove(handler->requests, key);
 			break;
 		case AUTH_REQUEST_STATE_PASSDB:
 		case AUTH_REQUEST_STATE_USERDB:
@@ -147,7 +145,7 @@
 	   request, so make sure we don't get back here. */
 	timeout_remove(&request->to_abort);
 
-	hash_table_remove(handler->requests, request->id);
+	hash_table_remove(handler->requests, POINTER_CAST(request->id));
 	auth_request_unref(&request);
 }
 
@@ -514,7 +512,7 @@
 		auth_request_unref(&request);
 		return FALSE;
 	}
-	if (hash_table_lookup(handler->requests, id) != NULL) {
+	if (hash_table_lookup(handler->requests, POINTER_CAST(id)) != NULL) {
 		i_error("BUG: Authentication client %u "
 			"sent a duplicate ID %u", handler->client_pid, id);
 		auth_request_unref(&request);
@@ -524,7 +522,7 @@
 
 	request->to_abort = timeout_add(MASTER_AUTH_SERVER_TIMEOUT_SECS * 1000,
 					auth_request_timeout, request);
-	hash_table_insert(handler->requests, id, request);
+	hash_table_insert(handler->requests, POINTER_CAST(id), request);
 
 	if (request->set->ssl_require_client_cert &&
 	    !request->valid_client_cert) {
@@ -579,7 +577,7 @@
 	}
 	data++;
 
-	request = hash_table_lookup(handler->requests, id);
+	request = hash_table_lookup(handler->requests, POINTER_CAST(id));
 	if (request == NULL) {
 		struct auth_stream_reply *reply;
 
@@ -686,7 +684,7 @@
 
 	reply = auth_stream_reply_init(pool_datastack_create());
 
-	request = hash_table_lookup(handler->requests, client_id);
+	request = hash_table_lookup(handler->requests, POINTER_CAST(client_id));
 	if (request == NULL) {
 		i_error("Master request %u.%u not found",
 			handler->client_pid, client_id);
@@ -731,7 +729,7 @@
 {
 	struct auth_request *request;
 
-	request = hash_table_lookup(handler->requests, client_id);
+	request = hash_table_lookup(handler->requests, POINTER_CAST(client_id));
 	if (request != NULL)
 		auth_request_handler_remove(handler, request);
 }
diff -r edb1d5babfcd -r 96fd2c3bf932 src/auth/db-checkpassword.c
--- a/src/auth/db-checkpassword.c	Mon Aug 20 08:31:00 2012 +0300
+++ b/src/auth/db-checkpassword.c	Mon Aug 20 09:47:28 2012 +0300
@@ -45,7 +45,7 @@
 struct db_checkpassword {
 	char *checkpassword_path, *checkpassword_reply_path;
 
-	HASH_TABLE(pid_t, struct chkpw_auth_request *) clients;
+	HASH_TABLE(void *, struct chkpw_auth_request *) clients;
 	struct child_wait *child_wait;
 };
 
@@ -89,7 +89,8 @@
 	*_request = NULL;
 
 	if (!request->exited) {
-		hash_table_remove(request->db->clients, request->pid);
+		hash_table_remove(request->db->clients,
+				  POINTER_CAST(request->pid));
 		child_wait_remove_pid(request->db->child_wait, request->pid);
 	}
 	checkpassword_request_close(request);
@@ -415,11 +416,11 @@
 			    struct db_checkpassword *db)
 {
 	struct chkpw_auth_request *request = 
-		hash_table_lookup(db->clients, status->pid);
+		hash_table_lookup(db->clients, POINTER_CAST(status->pid));
 
 	i_assert(request != NULL);
 
-	hash_table_remove(db->clients, status->pid);
+	hash_table_remove(db->clients, POINTER_CAST(status->pid));
 	request->exited = TRUE;
 
 	if (WIFSIGNALED(status->status)) {
@@ -531,7 +532,7 @@
 		io_add(fd_out[1], IO_WRITE, checkpassword_child_output,
 		       chkpw_auth_request);
 
-	hash_table_insert(db->clients, pid, chkpw_auth_request);
+	hash_table_insert(db->clients, POINTER_CAST(pid), chkpw_auth_request);
 	child_wait_add_pid(db->child_wait, pid);
 }
 
@@ -554,15 +555,14 @@
 {
 	struct db_checkpassword *db = *_db;
 	struct hash_iterate_context *iter;
-	void *key, *value;
+	void *key;
+	struct chkpw_auth_request *request;
 
 	*_db = NULL;
 
 	iter = hash_table_iterate_init(db->clients);
-	while (hash_table_iterate(iter, &key, &value)) {
-		struct chkpw_auth_request *request = value;
+	while (hash_table_iterate(iter, db->clients, &key, &request))
 		checkpassword_internal_failure(&request);
-	}
 	hash_table_iterate_deinit(&iter);
 
 	child_wait_free(&db->child_wait);
diff -r edb1d5babfcd -r 96fd2c3bf932 src/auth/db-ldap.c
--- a/src/auth/db-ldap.c	Mon Aug 20 08:31:00 2012 +0300
+++ b/src/auth/db-ldap.c	Mon Aug 20 09:47:28 2012 +0300
@@ -1324,7 +1324,7 @@
 	str_append(ctx->debug, "; ");
 
 	iter = hash_table_iterate_init(ctx->ldap_attrs);
-	while (hash_table_iterate_t(iter, ctx->ldap_attrs, &name, &value)) {
+	while (hash_table_iterate(iter, ctx->ldap_attrs, &name, &value)) {
 		if (!value->used) {
 			str_printfa(ctx->debug, "%s,", name);
 			unused_count++;
diff -r edb1d5babfcd -r 96fd2c3bf932 src/auth/db-passwd-file.c
--- a/src/auth/db-passwd-file.c	Mon Aug 20 08:31:00 2012 +0300
+++ b/src/auth/db-passwd-file.c	Mon Aug 20 09:47:28 2012 +0300
@@ -386,7 +386,7 @@
 		passwd_file_free(db->default_file);
 	else {
 		iter = hash_table_iterate_init(db->files);
-		while (hash_table_iterate_t(iter, db->files, &path, &file))
+		while (hash_table_iterate(iter, db->files, &path, &file))
 			passwd_file_free(file);
 		hash_table_iterate_deinit(&iter);
 		hash_table_destroy(&db->files);
diff -r edb1d5babfcd -r 96fd2c3bf932 src/director/director-test.c
--- a/src/director/director-test.c	Mon Aug 20 08:31:00 2012 +0300
+++ b/src/director/director-test.c	Mon Aug 20 09:47:28 2012 +0300
@@ -548,7 +548,10 @@
 static void main_deinit(void)
 {
 	struct hash_iterate_context *iter;
-	void *key, *value;
+	char *username;
+	struct ip_addr *ip;
+	struct user *user;
+	struct host *host;
 
 	while (imap_clients != NULL) {
 		struct imap_client *client = imap_clients;
@@ -562,18 +565,14 @@
 	}
 
 	iter = hash_table_iterate_init(users);
-	while (hash_table_iterate(iter, &key, &value)) {
-		struct user *user = value;
+	while (hash_table_iterate(iter, users, &username, &user))
 		user_free(user);
-	}
 	hash_table_iterate_deinit(&iter);
 	hash_table_destroy(&users);
 
 	iter = hash_table_iterate_init(hosts);
-	while (hash_table_iterate(iter, &key, &value)) {
-		struct host *host = value;
+	while (hash_table_iterate(iter, hosts, &ip, &host))
 		host_unref(&host);


More information about the dovecot-cvs mailing list