[dovecot-cvs] dovecot/src/lib-sql sql-api.h,1.11,1.12

tss at dovecot.org tss at dovecot.org
Fri Dec 15 18:11:04 UTC 2006


Update of /var/lib/cvs/dovecot/src/lib-sql
In directory talvi:/tmp/cvs-serv2752/lib-sql

Modified Files:
	sql-api.h 
Log Message:
Type safe callbacks weren't as easy as I thought. Only callback(void
*context) can be handled generically. Others can be handled specially, but
only if all the parameters are pointers, otherwise eg. int parameter can be
replaced with long without compiler giving any warnings.



Index: sql-api.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/sql-api.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- sql-api.h	15 Dec 2006 16:55:43 -0000	1.11
+++ sql-api.h	15 Dec 2006 18:11:00 -0000	1.12
@@ -45,9 +45,15 @@
 /* Execute SQL query and return result in callback. */
 void sql_query(struct sql_db *db, const char *query,
 	       sql_query_callback_t *callback, void *context);
-#define sql_query(db, query, callback, context) \
-	CONTEXT_CALLBACK2(sql_query, sql_query_callback_t, \
-			  callback, context, db, query)
+#ifdef CONTEXT_TYPE_SAFETY
+#  define sql_query(db, query, callback, context) \
+	({(void)(1 ? 0 : callback((struct sql_result *)NULL, context)); \
+	  sql_query(db, query, \
+		(sql_query_callback_t *)callback, context); })
+#else
+#  define sql_query(db, query, callback, context) \
+	  sql_query(db, query, (sql_query_callback_t *)callback, context)
+#endif
 /* Execute blocking SQL query and return result. */
 struct sql_result *sql_query_s(struct sql_db *db, const char *query);
 
@@ -83,9 +89,15 @@
 /* Commit transaction. */
 void sql_transaction_commit(struct sql_transaction_context **ctx,
 			    sql_commit_callback_t *callback, void *context);
-#define sql_transaction_commit(ctx, callback, context) \
-	CONTEXT_CALLBACK2(sql_transaction_commit, sql_commit_callback_t, \
-			  callback, context, ctx)
+#ifdef CONTEXT_TYPE_SAFETY
+#  define sql_transaction_commit(ctx, callback, context) \
+	({(void)(1 ? 0 : callback((const char *)NULL, context)); \
+	  sql_transaction_commit(ctx, \
+		(sql_query_callback_t *)callback, context); })
+#else
+#  define sql_transaction_commit(ctx, callback, context) \
+	  sql_transaction_commit(ctx, (sql_query_callback_t *)callback, context)
+#endif
 /* Synchronous commit. Returns 0 if ok, -1 if error. */
 int sql_transaction_commit_s(struct sql_transaction_context **ctx,
 			     const char **error_r);



More information about the dovecot-cvs mailing list