[dovecot-cvs] dovecot/src/plugins/fts Makefile.am, 1.2, 1.3 fts-storage.c, 1.19, 1.20

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


Update of /var/lib/cvs/dovecot/src/plugins/fts
In directory talvi:/tmp/cvs-serv16171/plugins/fts

Modified Files:
	Makefile.am fts-storage.c 
Log Message:
Better type safety to module_contexts arrays. Already fixed some bugs.



Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Makefile.am	15 Dec 2006 23:46:23 -0000	1.2
+++ Makefile.am	29 Mar 2007 11:51:10 -0000	1.3
@@ -1,6 +1,7 @@
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib \
 	-I$(top_srcdir)/src/lib-mail \
+	-I$(top_srcdir)/src/lib-index \
 	-I$(top_srcdir)/src/lib-storage
 
 lib20_fts_plugin_la_LDFLAGS = -module -avoid-version

Index: fts-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts/fts-storage.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- fts-storage.c	25 Mar 2007 18:45:01 -0000	1.19
+++ fts-storage.c	29 Mar 2007 11:51:10 -0000	1.20
@@ -15,14 +15,15 @@
 #include <stdlib.h>
 
 #define FTS_CONTEXT(obj) \
-	*((void **)array_idx_modifiable(&(obj)->module_contexts, \
-					fts_storage_module_id))
+	MODULE_CONTEXT(obj, fts_storage_module)
+#define FTS_MAIL_CONTEXT(obj) \
+	MODULE_CONTEXT(obj, fts_mail_module)
 
 #define FTS_SEARCH_NONBLOCK_COUNT 10
 #define FTS_BUILD_NOTIFY_INTERVAL_SECS 10
 
 struct fts_mailbox {
-	struct mailbox_vfuncs super;
+	union mailbox_module_context module_ctx;
 	struct fts_backend *backend_exact;
 	struct fts_backend *backend_fast;
 
@@ -31,6 +32,8 @@
 };
 
 struct fts_search_context {
+	union mail_search_module_context module_ctx;
+
 	ARRAY_TYPE(seq_range) result;
 	unsigned int result_pos;
 
@@ -58,15 +61,13 @@
 };
 
 struct fts_transaction_context {
+	union mailbox_transaction_module_context module_ctx;
 	bool expunges;
 };
 
-struct fts_mail {
-	struct mail_vfuncs super;
-};
-
-static unsigned int fts_storage_module_id = 0;
-static bool fts_storage_module_id_set = FALSE;
+static MODULE_CONTEXT_DEFINE_INIT(fts_storage_module,
+				  &mail_storage_module_register);
+static MODULE_CONTEXT_DEFINE_INIT(fts_mail_module, &mail_module_register);
 
 static int fts_mailbox_close(struct mailbox *box)
 {
@@ -78,7 +79,7 @@
 	if (fbox->backend_fast != NULL)
 		fts_backend_deinit(fbox->backend_fast);
 
-	ret = fbox->super.close(box);
+	ret = fbox->module_ctx.super.close(box);
 	i_free(fbox);
 	return ret;
 }
@@ -563,12 +564,13 @@
 	struct mail_search_arg *best_fast_arg, *best_exact_arg;
 	bool have_fast, have_exact;
 
-	ctx = fbox->super.search_init(t, charset, args, sort_program);
+	ctx = fbox->module_ctx.super.
+		search_init(t, charset, args, sort_program);
 
 	fctx = i_new(struct fts_search_context, 1);
 	fctx->t = t;
 	fctx->args = args;
-	array_idx_set(&ctx->module_contexts, fts_storage_module_id, &fctx);
+	MODULE_CONTEXT_SET(ctx, fts_storage_module, fctx);
 
 	if (fbox->backend_exact == NULL && fbox->backend_fast == NULL)
 		return ctx;
@@ -620,7 +622,8 @@
 		if (ret > 0)
 			fts_search_init(ctx->transaction->box, fctx);
 	}
-	return fbox->super.search_next_nonblock(ctx, mail, tryagain_r);
+	return fbox->module_ctx.super.
+		search_next_nonblock(ctx, mail, tryagain_r);
 
 }
 
@@ -634,7 +637,7 @@
 	int ret;
 
 	if (!array_is_created(&fctx->result))
-		return fbox->super.search_next_update_seq(ctx);
+		return fbox->module_ctx.super.search_next_update_seq(ctx);
 
 	do {
 		range = array_get_modifiable(&fctx->result, &count);
@@ -658,7 +661,7 @@
 		}
 
 		wanted_seq = ctx->seq + 1;
-		ret = fbox->super.search_next_update_seq(ctx);
+		ret = fbox->module_ctx.super.search_next_update_seq(ctx);
 	} while (ret > 0 && wanted_seq != ctx->seq);
 
 	return ret;
@@ -680,13 +683,13 @@
 	if (array_is_created(&fctx->result))
 		array_free(&fctx->result);
 	i_free(fctx);
-	return fbox->super.search_deinit(ctx);
+	return fbox->module_ctx.super.search_deinit(ctx);
 }
 
 static int fts_mail_expunge(struct mail *_mail)
 {
 	struct mail_private *mail = (struct mail_private *)_mail;
-	struct fts_mail *fmail = FTS_CONTEXT(mail);
+	union mail_module_context *fmail = FTS_MAIL_CONTEXT(mail);
 	struct fts_mailbox *fbox = FTS_CONTEXT(_mail->box);
 	struct fts_transaction_context *ft = FTS_CONTEXT(_mail->transaction);
 
@@ -707,20 +710,20 @@
 	       struct mailbox_header_lookup_ctx *wanted_headers)
 {
 	struct fts_mailbox *fbox = FTS_CONTEXT(t->box);
-	struct fts_mail *fmail;
+	union mail_module_context *fmail;
 	struct mail *_mail;
 	struct mail_private *mail;
 
-	_mail = fbox->super.mail_alloc(t, wanted_fields, wanted_headers);
+	_mail = fbox->module_ctx.super.
+		mail_alloc(t, wanted_fields, wanted_headers);
 	if (fbox->backend_exact != NULL || fbox->backend_fast != NULL) {
 		mail = (struct mail_private *)_mail;
 
-		fmail = p_new(mail->pool, struct fts_mail, 1);
+		fmail = p_new(mail->pool, union mail_module_context, 1);
 		fmail->super = mail->v;
 
 		mail->v.expunge = fts_mail_expunge;
-		array_idx_set(&mail->module_contexts,
-			      fts_storage_module_id, &fmail);
+		MODULE_CONTEXT_SET_SELF(mail, fts_mail_module, fmail);
 	}
 	return _mail;
 }
@@ -770,8 +773,8 @@
 		fbox->backend_set = TRUE;
 	}
 
-	t = fbox->super.transaction_begin(box, flags);
-	array_idx_set(&t->module_contexts, fts_storage_module_id, &ft);
+	t = fbox->module_ctx.super.transaction_begin(box, flags);
+	MODULE_CONTEXT_SET(t, fts_storage_module, ft);
 	return t;
 }
 
@@ -796,7 +799,7 @@
 	struct fts_mailbox *fbox = FTS_CONTEXT(box);
 	struct fts_transaction_context *ft = FTS_CONTEXT(t);
 
-	fbox->super.transaction_rollback(t);
+	fbox->module_ctx.super.transaction_rollback(t);
 	fts_transaction_finish(box, ft, FALSE);
 }
 
@@ -808,7 +811,7 @@
 	struct fts_transaction_context *ft = FTS_CONTEXT(t);
 	int ret;
 
-	ret = fbox->super.transaction_commit(t, flags);
+	ret = fbox->module_ctx.super.transaction_commit(t, flags);
 	fts_transaction_finish(box, ft, ret == 0);
 	return ret;
 }
@@ -827,7 +830,7 @@
 
 	fbox = i_new(struct fts_mailbox, 1);
 	fbox->env = env;
-	fbox->super = box->v;
+	fbox->module_ctx.super = box->v;
 	box->v.close = fts_mailbox_close;
 	box->v.search_init = fts_mailbox_search_init;
 	box->v.search_next_nonblock = fts_mailbox_search_next_nonblock;
@@ -838,10 +841,5 @@
 	box->v.transaction_rollback = fts_transaction_rollback;
 	box->v.transaction_commit = fts_transaction_commit;
 
-	if (!fts_storage_module_id_set) {
-		fts_storage_module_id = mail_storage_module_id++;
-		fts_storage_module_id_set = TRUE;
-	}
-
-	array_idx_set(&box->module_contexts, fts_storage_module_id, &fbox);
+	MODULE_CONTEXT_SET(box, fts_storage_module, fbox);
 }



More information about the dovecot-cvs mailing list