summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 982bbbc)
raw | patch | inline | side by side (parent: 982bbbc)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 26 Apr 2014 22:24:13 +0000 (00:24 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 26 Apr 2014 22:24:13 +0000 (00:24 +0200) |
src/utils/dbi.c | patch | blob | history | |
t/unit/utils/dbi_test.c | patch | blob | history |
diff --git a/src/utils/dbi.c b/src/utils/dbi.c
index de2348e713d34e82924bbf4870d252d186626803..b1fdaf127896aaf35863ec1a8cfd208c62982d6d 100644 (file)
--- a/src/utils/dbi.c
+++ b/src/utils/dbi.c
#include <stdlib.h>
#include <string.h>
+/*
+ * pre 0.9 DBI compat layer
+ */
+
+#if LIBDBI_VERSION < 900
+#include <pthread.h>
+
+typedef void *dbi_inst;
+
+static pthread_mutex_t dbi_lock = PTHREAD_MUTEX_INITIALIZER;
+static int dbi_initialized = 0;
+
+static int
+initialize_r(const char *driverdir, dbi_inst __attribute__((unused)) *pInst)
+{
+ int status = 0;
+ pthread_mutex_lock(&dbi_lock);
+ if (! dbi_initialized)
+ status = dbi_initialize(driverdir);
+ dbi_initialized = 1;
+ pthread_mutex_unlock(&dbi_lock);
+ return status;
+} /* initialize_r */
+
+static dbi_driver
+driver_open_r(const char *name, dbi_inst __attribute__((unused)) Inst)
+{
+ dbi_driver driver;
+ pthread_mutex_lock(&dbi_lock);
+ driver = dbi_driver_open(name);
+ pthread_mutex_unlock(&dbi_lock);
+ return driver;
+} /* driver_open_r */
+
+static dbi_driver
+driver_list_r(dbi_driver Current, dbi_inst __attribute__((unused)) Inst)
+{
+ dbi_driver driver;
+ pthread_mutex_lock(&dbi_lock);
+ driver = dbi_driver_list(Current);
+ pthread_mutex_unlock(&dbi_lock);
+ return driver;
+} /* driver_list_r */
+
+static void
+shutdown_r(dbi_inst __attribute__((unused)) Inst)
+{
+ /* do nothing; we don't know if DBI is still in use */
+} /* shutdown_r */
+
+#define dbi_initialize_r initialize_r
+#define dbi_driver_open_r driver_open_r
+#define dbi_driver_list_r driver_list_r
+#define dbi_shutdown_r shutdown_r
+#endif /* LIBDBI_VERSION < 900 */
+
/*
* private data types
*/
index 8a21acebe66f8bd2bcc3007918ecc8888388d386..8a0811bda72a71670a8aa921cf1c0bc7f3e33126 100644 (file)
--- a/t/unit/utils/dbi_test.c
+++ b/t/unit/utils/dbi_test.c
/* dbi_driver, dbi_conn, dbi_result are void pointers */
+#if LIBDBI_VERSION < 900
+typedef void *dbi_inst;
+
+int
+dbi_initialize_r(const char *driverdir, dbi_inst *pInst);
+void
+dbi_shutdown_r(dbi_inst inst);
+dbi_driver
+dbi_driver_open_r(const char *name, dbi_inst inst);
+dbi_driver
+dbi_driver_list_r(dbi_driver curr, dbi_inst inst);
+#endif
+
int
dbi_initialize_r(const char __attribute__((unused)) *driverdir,
dbi_inst __attribute__((unused)) *pInst)
return NULL;
} /* dbi_driver_list */
+#if LIBDBI_VERSION < 900
+int
+dbi_initialize(const char *driverdir)
+{
+ return dbi_initialize_r(driverdir, NULL);
+} /* dbi_initialize */
+
+/* for some weird reason, gcc and clang complain about a missing prototype for
+ * dbi_shutdown; however, the function is declared in dbi/dbi.h */
+void
+dbi_shutdown(void);
+void
+dbi_shutdown(void)
+{
+ dbi_shutdown_r(NULL);
+} /* dbi_shutdown */
+
+dbi_driver
+dbi_driver_open(const char *name)
+{
+ return dbi_driver_open_r(name, NULL);
+} /* dbi_driver_open */
+
+dbi_driver
+dbi_driver_list(dbi_driver curr)
+{
+ return dbi_driver_list_r(curr, NULL);
+} /* dbi_driver_list */
+#endif
+
const char *
dbi_driver_get_name(dbi_driver driver)
{