dovecot-2.0: SQL API change: SQL results can be now refed/unrefed.
dovecot at dovecot.org
dovecot at dovecot.org
Wed May 13 02:35:02 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/f9ebd72a73e8
changeset: 9270:f9ebd72a73e8
user: Timo Sirainen <tss at iki.fi>
date: Tue May 12 19:34:06 2009 -0400
description:
SQL API change: SQL results can be now refed/unrefed.
diffstat:
7 files changed, 29 insertions(+), 12 deletions(-)
src/lib-dict/dict-sql.c | 4 ++--
src/lib-sql/driver-mysql.c | 8 +++++---
src/lib-sql/driver-pgsql.c | 6 ++++--
src/lib-sql/driver-sqlite.c | 3 ++-
src/lib-sql/sql-api-private.h | 1 +
src/lib-sql/sql-api.c | 13 +++++++++++--
src/lib-sql/sql-api.h | 6 ++++--
diffs (167 lines):
diff -r 2eecf682262a -r f9ebd72a73e8 src/lib-dict/dict-sql.c
--- a/src/lib-dict/dict-sql.c Tue May 12 18:55:02 2009 -0400
+++ b/src/lib-dict/dict-sql.c Tue May 12 19:34:06 2009 -0400
@@ -290,7 +290,7 @@ static int sql_dict_lookup(struct dict *
p_strdup(pool, sql_result_get_field_value(result, 0));
}
- sql_result_free(result);
+ sql_result_unref(result);
return ret;
}
@@ -444,7 +444,7 @@ static void sql_dict_iterate_deinit(stru
(struct sql_dict_iterate_context *)_ctx;
if (ctx->result != NULL)
- sql_result_free(ctx->result);
+ sql_result_unref(ctx->result);
str_free(&ctx->key);
i_free(ctx->path);
i_free(ctx);
diff -r 2eecf682262a -r f9ebd72a73e8 src/lib-sql/driver-mysql.c
--- a/src/lib-sql/driver-mysql.c Tue May 12 18:55:02 2009 -0400
+++ b/src/lib-sql/driver-mysql.c Tue May 12 19:34:06 2009 -0400
@@ -419,7 +419,7 @@ static void driver_mysql_query(struct sq
result->callback = TRUE;
callback(result, context);
result->callback = FALSE;
- sql_result_free(result);
+ sql_result_unref(result);
}
static struct sql_result *
@@ -450,6 +450,7 @@ driver_mysql_query_s(struct sql_db *_db,
break;
}
+ result->api.refcount = 1;
result->conn = conn;
return &result->api;
}
@@ -458,7 +459,8 @@ static void driver_mysql_result_free(str
{
struct mysql_result *result = (struct mysql_result *)_result;
- if (_result == &sql_not_connected_result || _result->callback)
+ i_assert(_result != &sql_not_connected_result);
+ if (_result->callback)
return;
if (result->result != NULL)
@@ -607,7 +609,7 @@ static int transaction_send_query(struct
ctx->failed = TRUE;
ret = -1;
}
- sql_result_free(result);
+ sql_result_unref(result);
return ret;
}
diff -r 2eecf682262a -r f9ebd72a73e8 src/lib-sql/driver-pgsql.c
--- a/src/lib-sql/driver-pgsql.c Tue May 12 18:55:02 2009 -0400
+++ b/src/lib-sql/driver-pgsql.c Tue May 12 19:34:06 2009 -0400
@@ -351,7 +351,7 @@ static void result_finish(struct pgsql_r
}
}
if (free_result)
- driver_pgsql_result_free(&result->api);
+ sql_result_unref(&result->api);
}
static void get_result(struct pgsql_result *result)
@@ -582,6 +582,7 @@ static void driver_pgsql_exec_full(struc
result = i_new(struct pgsql_result, 1);
result->api = driver_pgsql_result;
result->api.db = db;
+ result->api.refcount = 1;
result->callback = exec_callback;
if (retry_query) {
result->query = i_strdup(query);
@@ -605,6 +606,7 @@ driver_pgsql_query_full(struct sql_db *d
result = i_new(struct pgsql_result, 1);
result->api = driver_pgsql_result;
result->api.db = db;
+ result->api.refcount = 1;
result->callback = callback;
result->context = context;
if (retry_query) {
@@ -995,7 +997,7 @@ driver_pgsql_transaction_commit_s(struct
*error_r = sql_result_get_error(result);
}
if (result != NULL)
- sql_result_free(result);
+ sql_result_unref(result);
i_assert(ctx->refcount == 1);
driver_pgsql_transaction_unref(ctx);
diff -r 2eecf682262a -r f9ebd72a73e8 src/lib-sql/driver-sqlite.c
--- a/src/lib-sql/driver-sqlite.c Tue May 12 18:55:02 2009 -0400
+++ b/src/lib-sql/driver-sqlite.c Tue May 12 19:34:06 2009 -0400
@@ -143,7 +143,7 @@ static void driver_sqlite_query(struct s
result->callback = TRUE;
callback(result, context);
result->callback = FALSE;
- sql_result_free(result);
+ sql_result_unref(result);
}
static struct sql_result *
@@ -172,6 +172,7 @@ driver_sqlite_query_s(struct sql_db *_db
}
}
result->api.db = _db;
+ result->api.refcount = 1;
return &result->api;
}
diff -r 2eecf682262a -r f9ebd72a73e8 src/lib-sql/sql-api-private.h
--- a/src/lib-sql/sql-api-private.h Tue May 12 18:55:02 2009 -0400
+++ b/src/lib-sql/sql-api-private.h Tue May 12 19:34:06 2009 -0400
@@ -73,6 +73,7 @@ struct sql_field_map {
struct sql_result {
struct sql_result_vfuncs v;
+ int refcount;
struct sql_db *db;
const struct sql_field_def *fields;
diff -r 2eecf682262a -r f9ebd72a73e8 src/lib-sql/sql-api.c
--- a/src/lib-sql/sql-api.c Tue May 12 18:55:02 2009 -0400
+++ b/src/lib-sql/sql-api.c Tue May 12 19:34:06 2009 -0400
@@ -97,8 +97,17 @@ struct sql_result *sql_query_s(struct sq
return db->v.query_s(db, query);
}
-void sql_result_free(struct sql_result *result)
-{
+void sql_result_ref(struct sql_result *result)
+{
+ result->refcount++;
+}
+
+void sql_result_unref(struct sql_result *result)
+{
+ i_assert(result->refcount > 0);
+ if (--result->refcount > 0)
+ return;
+
i_free(result->map);
result->v.free(result);
}
diff -r 2eecf682262a -r f9ebd72a73e8 src/lib-sql/sql-api.h
--- a/src/lib-sql/sql-api.h Tue May 12 18:55:02 2009 -0400
+++ b/src/lib-sql/sql-api.h Tue May 12 19:34:06 2009 -0400
@@ -94,8 +94,10 @@ void sql_result_setup_fetch(struct sql_r
occurred. This needs to be the first call for result. */
int sql_result_next_row(struct sql_result *result);
-/* Needs to be called only with sql_query_s(). */
-void sql_result_free(struct sql_result *result);
+void sql_result_ref(struct sql_result *result);
+/* Needs to be called only with sql_query_s() or when result has been
+ explicitly referenced. */
+void sql_result_unref(struct sql_result *result);
/* Return number of fields in result. */
unsigned int sql_result_get_fields_count(struct sql_result *result);
More information about the dovecot-cvs
mailing list