dovecot-1.2: dict API: deinit functions now take pointer-to-poin...

dovecot at dovecot.org dovecot at dovecot.org
Wed Aug 27 08:07:57 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/b46b0158eb64
changeset: 8108:b46b0158eb64
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Aug 27 08:07:51 2008 +0300
description:
dict API: deinit functions now take pointer-to-pointer parameter which gets NULLed.

diffstat:

6 files changed, 27 insertions(+), 18 deletions(-)
src/dict/dict-server.c             |   12 ++++++------
src/lib-dict/dict.c                |   15 ++++++++++++---
src/lib-dict/dict.h                |    6 +++---
src/plugins/expire/expire-plugin.c |    2 +-
src/plugins/expire/expire-tool.c   |    6 +++---
src/plugins/quota/quota-dict.c     |    4 ++--

diffs (161 lines):

diff -r dfae8a7d695b -r b46b0158eb64 src/dict/dict-server.c
--- a/src/dict/dict-server.c	Wed Aug 27 08:06:17 2008 +0300
+++ b/src/dict/dict-server.c	Wed Aug 27 08:07:51 2008 +0300
@@ -99,7 +99,7 @@ static int cmd_iterate(struct dict_clien
 			o_stream_send_str(conn->output, reply);
 		} T_END;
 	}
-	dict_iterate_deinit(ctx);
+	dict_iterate_deinit(&ctx);
 
 	o_stream_send_str(conn->output, "\n");
 	o_stream_uncork(conn->output);
@@ -196,7 +196,7 @@ static int cmd_commit(struct dict_client
 	if (dict_server_transaction_lookup_parse(conn, line, &trans) < 0)
 		return -1;
 
-	ret = dict_transaction_commit(trans->ctx);
+	ret = dict_transaction_commit(&trans->ctx);
 	reply = t_strdup_printf("%c\n", ret == 0 ? DICT_PROTOCOL_REPLY_OK :
 				DICT_PROTOCOL_REPLY_FAIL);
 	o_stream_send_str(conn->output, reply);
@@ -211,7 +211,7 @@ static int cmd_rollback(struct dict_clie
 	if (dict_server_transaction_lookup_parse(conn, line, &trans) < 0)
 		return -1;
 
-	dict_transaction_rollback(trans->ctx);
+	dict_transaction_rollback(&trans->ctx);
 	dict_server_transaction_array_remove(conn, trans);
 	return 0;
 }
@@ -414,7 +414,7 @@ static void dict_client_connection_input
 
 static void dict_client_connection_deinit(struct dict_client_connection *conn)
 {
-	const struct dict_server_transaction *transactions;
+	struct dict_server_transaction *transactions;
 	unsigned int i, count;
 
 	if (conn->prev == NULL)
@@ -425,9 +425,9 @@ static void dict_client_connection_deini
 		conn->next->prev = conn->prev;
 
 	if (array_is_created(&conn->transactions)) {
-		transactions = array_get(&conn->transactions, &count);
+		transactions = array_get_modifiable(&conn->transactions, &count);
 		for (i = 0; i < count; i++)
-			dict_transaction_rollback(transactions[i].ctx);
+			dict_transaction_rollback(&transactions[i].ctx);
 		array_free(&conn->transactions);
 	}
 
diff -r dfae8a7d695b -r b46b0158eb64 src/lib-dict/dict.c
--- a/src/lib-dict/dict.c	Wed Aug 27 08:06:17 2008 +0300
+++ b/src/lib-dict/dict.c	Wed Aug 27 08:07:51 2008 +0300
@@ -103,8 +103,11 @@ int dict_iterate(struct dict_iterate_con
 	return ctx->dict->v.iterate(ctx, key_r, value_r);
 }
 
-void dict_iterate_deinit(struct dict_iterate_context *ctx)
+void dict_iterate_deinit(struct dict_iterate_context **_ctx)
 {
+	struct dict_iterate_context *ctx = *_ctx;
+
+	*_ctx = NULL;
 	ctx->dict->v.iterate_deinit(ctx);
 }
 
@@ -113,13 +116,19 @@ struct dict_transaction_context *dict_tr
 	return dict->v.transaction_init(dict);
 }
 
-int dict_transaction_commit(struct dict_transaction_context *ctx)
+int dict_transaction_commit(struct dict_transaction_context **_ctx)
 {
+	struct dict_transaction_context *ctx = *_ctx;
+
+	*_ctx = NULL;
 	return ctx->dict->v.transaction_commit(ctx);
 }
 
-void dict_transaction_rollback(struct dict_transaction_context *ctx)
+void dict_transaction_rollback(struct dict_transaction_context **_ctx)
 {
+	struct dict_transaction_context *ctx = *_ctx;
+
+	*_ctx = NULL;
 	ctx->dict->v.transaction_rollback(ctx);
 }
 
diff -r dfae8a7d695b -r b46b0158eb64 src/lib-dict/dict.h
--- a/src/lib-dict/dict.h	Wed Aug 27 08:06:17 2008 +0300
+++ b/src/lib-dict/dict.h	Wed Aug 27 08:07:51 2008 +0300
@@ -43,14 +43,14 @@ dict_iterate_init(struct dict *dict, con
 /* Returns -1 = error, 0 = finished, 1 = key/value set */
 int dict_iterate(struct dict_iterate_context *ctx,
 		 const char **key_r, const char **value_r);
-void dict_iterate_deinit(struct dict_iterate_context *ctx);
+void dict_iterate_deinit(struct dict_iterate_context **ctx);
 
 /* Start a new dictionary transaction. */
 struct dict_transaction_context *dict_transaction_begin(struct dict *dict);
 /* Commit the transaction. Returns 0 if ok, -1 if failed. */
-int dict_transaction_commit(struct dict_transaction_context *ctx);
+int dict_transaction_commit(struct dict_transaction_context **ctx);
 /* Rollback all changes made in transaction. */
-void dict_transaction_rollback(struct dict_transaction_context *ctx);
+void dict_transaction_rollback(struct dict_transaction_context **ctx);
 
 /* Set key=value in dictionary. */
 void dict_set(struct dict_transaction_context *ctx,
diff -r dfae8a7d695b -r b46b0158eb64 src/plugins/expire/expire-plugin.c
--- a/src/plugins/expire/expire-plugin.c	Wed Aug 27 08:06:17 2008 +0300
+++ b/src/plugins/expire/expire-plugin.c	Wed Aug 27 08:07:51 2008 +0300
@@ -147,7 +147,7 @@ expire_mailbox_transaction_commit(struct
 				new_stamp += xpr_box->expire_secs;
 				dict_set(dctx, key, dec2str(new_stamp));
 			}
-			dict_transaction_commit(dctx);
+			dict_transaction_commit(&dctx);
 		}
 	} T_END;
 	i_free(xt);
diff -r dfae8a7d695b -r b46b0158eb64 src/plugins/expire/expire-tool.c
--- a/src/plugins/expire/expire-tool.c	Wed Aug 27 08:06:17 2008 +0300
+++ b/src/plugins/expire/expire-tool.c	Wed Aug 27 08:07:51 2008 +0300
@@ -278,11 +278,11 @@ static void expire_run(bool testrun)
 			}
 		}
 	}
-	dict_iterate_deinit(iter);
+	dict_iterate_deinit(&iter);
 	if (!testrun)
-		dict_transaction_commit(trans);
+		dict_transaction_commit(&trans);
 	else
-		dict_transaction_rollback(trans);
+		dict_transaction_rollback(&trans);
 	dict_deinit(&dict);
 
 	if (ctx.user != NULL)
diff -r dfae8a7d695b -r b46b0158eb64 src/plugins/quota/quota-dict.c
--- a/src/plugins/quota/quota-dict.c	Wed Aug 27 08:06:17 2008 +0300
+++ b/src/plugins/quota/quota-dict.c	Wed Aug 27 08:07:51 2008 +0300
@@ -97,7 +97,7 @@ dict_quota_count(struct dict_quota_root 
 		dict_set(dt, DICT_QUOTA_CURRENT_COUNT_PATH, dec2str(count));
 	} T_END;
 
-	if (dict_transaction_commit(dt) < 0)
+	if (dict_transaction_commit(&dt) < 0)
 		i_error("dict_quota: Couldn't update quota");
 
 	*value_r = want_bytes ? bytes : count;
@@ -167,7 +167,7 @@ dict_quota_update(struct quota_root *_ro
 		}
 	}
 	
-	if (dict_transaction_commit(dt) < 0)
+	if (dict_transaction_commit(&dt) < 0)
 		return -1;
 	return 0;
 }


More information about the dovecot-cvs mailing list