[dovecot-cvs] dovecot/src/lib-storage/list index-mailbox-list-sync.c, 1.6, 1.7 index-mailbox-list.c, 1.8, 1.9 index-mailbox-list.h, 1.2, 1.3

tss at dovecot.org tss at dovecot.org
Thu Mar 29 14:51:33 EEST 2007


Update of /var/lib/cvs/dovecot/src/lib-storage/list
In directory talvi:/tmp/cvs-serv16171/lib-storage/list

Modified Files:
	index-mailbox-list-sync.c index-mailbox-list.c 
	index-mailbox-list.h 
Log Message:
Better type safety to module_contexts arrays. Already fixed some bugs.



Index: index-mailbox-list-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/list/index-mailbox-list-sync.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- index-mailbox-list-sync.c	29 Mar 2007 07:59:24 -0000	1.6
+++ index-mailbox-list-sync.c	29 Mar 2007 11:51:29 -0000	1.7
@@ -11,15 +11,14 @@
 #include <sys/stat.h>
 
 #define INDEX_LIST_STORAGE_CONTEXT(obj) \
-	*((void **)array_idx_modifiable(&(obj)->module_contexts, \
-					index_list_storage_module_id))
+	MODULE_CONTEXT(obj, index_list_storage_module)
 
 #define CACHED_STATUS_ITEMS \
 	(STATUS_MESSAGES | STATUS_UNSEEN | STATUS_RECENT | \
 	 STATUS_UIDNEXT | STATUS_UIDVALIDITY)
 
 struct index_list_mailbox {
-	struct mailbox_vfuncs super;
+	union mailbox_module_context module_ctx;
 
 	uint32_t log_seq;
 	uoff_t log_offset;
@@ -45,14 +44,14 @@
 
 static void (*index_list_next_hook_mailbox_created)(struct mailbox *box);
 
-static unsigned int index_list_storage_module_id = 0;
-static bool index_list_storage_module_id_set = FALSE;
+static MODULE_CONTEXT_DEFINE_INIT(index_list_storage_module,
+				  &mail_storage_module_register);
 
 static int index_list_box_close(struct mailbox *box)
 {
 	struct index_list_mailbox *ibox = INDEX_LIST_STORAGE_CONTEXT(box);
 
-	return ibox->super.close(box);
+	return ibox->module_ctx.super.close(box);
 }
 
 static int index_list_update_mail_index(struct index_mailbox_list *ilist,
@@ -251,7 +250,7 @@
 		/* nonsynced / error, fallback to doing it the slow way */
 	}
 
-	return ibox->super.get_status(box, items, status);
+	return ibox->module_ctx.super.get_status(box, items, status);
 }
 
 static int index_list_lookup_or_create(struct index_mailbox_list *ilist,
@@ -397,7 +396,7 @@
 		}
 	}
 
-	return ibox->super.sync_init(box, flags);
+	return ibox->module_ctx.super.sync_init(box, flags);
 }
 
 static int index_list_sync_next(struct mailbox_sync_context *ctx,
@@ -408,7 +407,7 @@
 	if (!ctx->box->opened)
 		return 0;
 
-	return ibox->super.sync_next(ctx, sync_rec_r);
+	return ibox->module_ctx.super.sync_next(ctx, sync_rec_r);
 }
 
 static int index_list_sync_deinit(struct mailbox_sync_context *ctx,
@@ -436,7 +435,8 @@
 
 	if (ilist == NULL) {
 		/* indexing disabled */
-		return ibox->super.sync_deinit(ctx, status_items, status_r);
+		return ibox->module_ctx.super.
+			sync_deinit(ctx, status_items, status_r);
 	}
 
 	/* if status_items == 0, the status_r may be NULL. we really want to
@@ -444,7 +444,7 @@
 	status = status_items == 0 ? &tmp_status : status_r;
 	status_items |= CACHED_STATUS_ITEMS;
 
-	if (ibox->super.sync_deinit(ctx, status_items, status) < 0)
+	if (ibox->module_ctx.super.sync_deinit(ctx, status_items, status) < 0)
 		return -1;
 	ctx = NULL;
 
@@ -474,20 +474,14 @@
 		return;
 
 	ibox = p_new(box->pool, struct index_list_mailbox, 1);
-	ibox->super = box->v;
+	ibox->module_ctx.super = box->v;
 	box->v.close = index_list_box_close;
 	box->v.get_status = index_list_get_status;
 	box->v.sync_init = index_list_sync_init;
 	box->v.sync_next = index_list_sync_next;
 	box->v.sync_deinit = index_list_sync_deinit;
 
-	if (!index_list_storage_module_id_set) {
-		index_list_storage_module_id = mail_storage_module_id++;
-		index_list_storage_module_id_set = TRUE;
-	}
-
-	array_idx_set(&box->module_contexts,
-		      index_list_storage_module_id, &ibox);
+	MODULE_CONTEXT_SET(box, index_list_storage_module, ibox);
 }
 
 void index_mailbox_list_sync_init_list(struct mailbox_list *list)

Index: index-mailbox-list.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/list/index-mailbox-list.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- index-mailbox-list.c	15 Mar 2007 13:34:50 -0000	1.8
+++ index-mailbox-list.c	29 Mar 2007 11:51:29 -0000	1.9
@@ -16,9 +16,8 @@
 /* min 2 seconds */
 #define MAILBOX_LIST_SYNC_SECS 2
 
-unsigned int index_mailbox_list_module_id = 0;
-
-static bool index_mailbox_list_module_id_set = FALSE;
+struct index_mailbox_list_module index_mailbox_list_module =
+	MODULE_CONTEXT_INIT(&mailbox_list_module_register);
 static void (*index_next_hook_mailbox_list_created)(struct mailbox_list *list);
 
 static int
@@ -151,7 +150,8 @@
 								ctx->sync_ctx);
 		}
 
-		ctx->backend_ctx = ilist->super.iter_init(list, mask, flags);
+		ctx->backend_ctx = ilist->module_ctx.super.
+			iter_init(list, mask, flags);
 	}
 	return &ctx->ctx;
 }
@@ -271,7 +271,7 @@
 	}
 
 	do {
-		info = ilist->super.iter_next(ctx->backend_ctx);
+		info = ilist->module_ctx.super.iter_next(ctx->backend_ctx);
 		if (info == NULL || ctx->sync_ctx == NULL)
 			return info;
 
@@ -314,7 +314,8 @@
 			offsetof(struct mail_index_header, sync_stamp),
 			&ctx->sync_stamp, sizeof(ctx->sync_stamp), TRUE);
 
-		if ((ret = ilist->super.iter_deinit(ctx->backend_ctx)) < 0)
+		ret = ilist->module_ctx.super.iter_deinit(ctx->backend_ctx);
+		if (ret < 0)
 			mailbox_list_index_sync_rollback(&ctx->sync_ctx);
 		else {
 			/* index updates aren't that important. if the commit
@@ -322,7 +323,7 @@
 			(void)mailbox_list_index_sync_commit(&ctx->sync_ctx);
 		}
 	} else if (ctx->backend_ctx != NULL) {
-		ret = ilist->super.iter_deinit(ctx->backend_ctx);
+		ret = ilist->module_ctx.super.iter_deinit(ctx->backend_ctx);
 	}
 
 	imap_match_deinit(&ctx->glob);
@@ -339,7 +340,7 @@
 	mailbox_list_index_view_deinit(&ilist->list_sync_view);
 	mail_index_free(&ilist->mail_index);
 
-	ilist->super.deinit(list);
+	ilist->module_ctx.super.deinit(list);
 }
 
 static int index_mailbox_list_open_indexes(struct mailbox_list *list,
@@ -400,20 +401,13 @@
 		return;
 
 	ilist = p_new(list->pool, struct index_mailbox_list, 1);
-	ilist->super = list->v;
+	ilist->module_ctx.super = list->v;
 
 	list->v.deinit = index_mailbox_list_deinit;
 	list->v.iter_init = index_mailbox_list_iter_init;
 	list->v.iter_deinit = index_mailbox_list_iter_deinit;
 	list->v.iter_next = index_mailbox_list_iter_next;
-
-	if (!index_mailbox_list_module_id_set) {
-		index_mailbox_list_module_id = mailbox_list_module_id++;
-		index_mailbox_list_module_id_set = TRUE;
-	}
-
-	array_idx_set(&list->module_contexts,
-		      index_mailbox_list_module_id, &ilist);
+	MODULE_CONTEXT_SET(list, index_mailbox_list_module, ilist);
 
 	dir = mailbox_list_get_path(list, NULL, MAILBOX_LIST_PATH_TYPE_INDEX);
 	ilist->mail_index = mail_index_alloc(dir, MAIL_INDEX_PREFIX);
@@ -424,10 +418,9 @@
 	index_mailbox_list_sync_init_list(list);
 
 	if (index_mailbox_list_open_indexes(list, dir) < 0) {
-		list->v = ilist->super;
+		list->v = ilist->module_ctx.super;
 		mail_index_free(&ilist->mail_index);
-		array_idx_clear(&list->module_contexts,
-				index_mailbox_list_module_id);
+		MODULE_CONTEXT_UNSET(list, index_mailbox_list_module);
 	}
 }
 

Index: index-mailbox-list.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/list/index-mailbox-list.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- index-mailbox-list.h	15 Mar 2007 13:34:50 -0000	1.2
+++ index-mailbox-list.h	29 Mar 2007 11:51:29 -0000	1.3
@@ -1,17 +1,17 @@
 #ifndef __INDEX_MAILBOX_LIST_H
 #define __INDEX_MAILBOX_LIST_H
 
+#include "module-context.h"
 #include "mailbox-list-private.h"
 
 #define MAIL_INDEX_PREFIX "dovecot.list.index"
 #define MAILBOX_LIST_INDEX_NAME MAIL_INDEX_PREFIX".uidmap"
 
 #define INDEX_LIST_CONTEXT(obj) \
-	*((void **)array_idx_modifiable(&(obj)->module_contexts, \
-					index_mailbox_list_module_id))
+	MODULE_CONTEXT(obj, index_mailbox_list_module)
 
 struct index_mailbox_list {
-	struct mailbox_list_vfuncs super;
+	union mailbox_list_module_context module_ctx;
 
 	struct mail_index *mail_index;
 	struct mailbox_list_index *list_index;
@@ -45,7 +45,8 @@
 	unsigned int failed:1;
 };
 
-extern unsigned int index_mailbox_list_module_id;
+extern MODULE_CONTEXT_DEFINE(index_mailbox_list_module,
+			     &mailbox_list_module_register);
 
 void index_mailbox_list_sync_init(void);
 void index_mailbox_list_sync_init_list(struct mailbox_list *list);



More information about the dovecot-cvs mailing list