From d0701903aa3271ab62137cc2630edbf94bc340a4 Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Sun, 12 Oct 2014 21:35:15 +0400 Subject: [PATCH] Use single codebase for all Erlang versions --- .travis.yml | 2 ++ README.md | 2 +- c_src/sqlite3_drv.c | 50 +++++++++++++++++++++++++++++++++++++-------- c_src/sqlite3_drv.h | 11 ++++++++++ 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5c5d590..65c5477 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,5 @@ script: "make test" otp_release: - 17.1 - R16B03-1 + - R15B03 + - R14B04 \ No newline at end of file diff --git a/README.md b/README.md index 9a93bfd..0dc69d9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ See also [esqlite](https://github.com/mmzeeman/esqlite) for an alternative libra ## Requirements -Erlang/OTP R16B or 17.x is required, and SQLite 3 minimum version is 3.6.1. See R14B branch for older Erlang versions. +Erlang/OTP R14B or later is required (tested up to 17.3 at this writing), and SQLite 3 minimum version is 3.6.1. ## Compiling diff --git a/c_src/sqlite3_drv.c b/c_src/sqlite3_drv.c index 9bf9c12..beb1e12 100644 --- a/c_src/sqlite3_drv.c +++ b/c_src/sqlite3_drv.c @@ -285,7 +285,12 @@ static inline int output_error( term_count += 2; dataset[11] = ERL_DRV_TUPLE; dataset[12] = 2; - erl_drv_output_term(dataset[1], dataset, term_count); + #ifdef PRE_R16B + driver_output_term(drv->port, + #else + erl_drv_output_term(dataset[1], + #endif + dataset, term_count); driver_free(dataset); return 0; } @@ -301,7 +306,13 @@ static inline int output_ok(sqlite3_drv_t *drv) { ERL_DRV_ATOM, drv->atom_ok, ERL_DRV_TUPLE, 2 }; - return erl_drv_output_term(spec[1], spec, sizeof(spec) / sizeof(spec[0])); + return + #ifdef PRE_R16B + driver_output_term(drv->port, + #else + erl_drv_output_term(spec[1], + #endif + spec, sizeof(spec) / sizeof(spec[0])); } static int enable_load_extension(sqlite3_drv_t* drv, char *buf, int len) { @@ -990,10 +1001,14 @@ static void ready_async(ErlDrvData drv_data, ErlDrvThreadData thread_data) { (async_sqlite3_command *) thread_data; sqlite3_drv_t *drv = async_command->driver_data; - int res = erl_drv_output_term(driver_mk_port(drv->port), - async_command->dataset, - async_command->term_count); - (void) res; // suppress unused warning + int res = + #ifdef PRE_R16B + driver_output_term(drv->port, + #else + erl_drv_output_term(driver_mk_port(drv->port), + #endif + async_command->dataset, + async_command->term_count); if (res != 1) { LOG_DEBUG("driver_output_term returned %d\n", res); #ifdef DEBUG @@ -1035,7 +1050,13 @@ static int prepare(sqlite3_drv_t *drv, char *command, int command_size) { spec[3] = drv->prepared_count - 1; spec[4] = ERL_DRV_TUPLE; spec[5] = 2; - return erl_drv_output_term(spec[1], spec, sizeof(spec) / sizeof(spec[0])); + return + #ifdef PRE_R16B + driver_output_term(drv->port, + #else + erl_drv_output_term(spec[1], + #endif + spec, sizeof(spec) / sizeof(spec[0])); } static int prepared_bind(sqlite3_drv_t *drv, char *buffer, int buffer_size) { @@ -1102,7 +1123,12 @@ static int prepared_columns(sqlite3_drv_t *drv, char *buffer, int buffer_size) { EXTEND_DATASET_DIRECT(2); append_to_dataset(2, dataset, term_count, ERL_DRV_TUPLE, (ErlDrvTermData) 2); - erl_drv_output_term(port, dataset, term_count); + #ifdef PRE_R16B + driver_output_term(drv->port, + #else + erl_drv_output_term(port, + #endif + dataset, term_count); free_ptr_list(ptrs, driver_free_fun); driver_free(dataset); return 0; @@ -1225,7 +1251,13 @@ static int unknown(sqlite3_drv_t *drv, char *command, int command_size) { ERL_DRV_ATOM, drv->atom_unknown_cmd, ERL_DRV_TUPLE, 4 }; - return erl_drv_output_term(spec[1], spec, sizeof(spec) / sizeof(spec[0])); + return + #ifdef PRE_R16B + driver_output_term(drv->port, + #else + erl_drv_output_term(spec[1], + #endif + spec, sizeof(spec) / sizeof(spec[0])); } static inline ptr_list *add_to_ptr_list(ptr_list *list, void *value_ptr) { diff --git a/c_src/sqlite3_drv.h b/c_src/sqlite3_drv.h index b6ba59d..98d1ab9 100644 --- a/c_src/sqlite3_drv.h +++ b/c_src/sqlite3_drv.h @@ -19,6 +19,17 @@ #error "SQLite3 of version 3.6.1 minumum required" #endif +// pre-R15B +#if ERL_DRV_EXTENDED_MAJOR_VERSION < 2 +typedef int ErlDrvSizeT; +typedef int ErlDrvSSizeT; +#endif + +// pre-R16B +#if (ERL_DRV_EXTENDED_MAJOR_VERSION < 2) || ((ERL_DRV_EXTENDED_MAJOR_VERSION == 2) && (ERL_DRV_EXTENDED_MINOR_VERSION == 0)) +#define PRE_R16B +#endif + #if defined(_MSC_VER) #pragma warning(disable: 4201) #pragma warning(disable: 4127)