Use single codebase for all Erlang versions

This commit is contained in:
Alexey Romanov
2014-10-12 21:35:15 +04:00
parent ed2ae9d2a9
commit d0701903aa
4 changed files with 55 additions and 10 deletions

View File

@@ -3,3 +3,5 @@ script: "make test"
otp_release: otp_release:
- 17.1 - 17.1
- R16B03-1 - R16B03-1
- R15B03
- R14B04

View File

@@ -10,7 +10,7 @@ See also [esqlite](https://github.com/mmzeeman/esqlite) for an alternative libra
## Requirements ## 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 ## Compiling

View File

@@ -285,7 +285,12 @@ static inline int output_error(
term_count += 2; term_count += 2;
dataset[11] = ERL_DRV_TUPLE; dataset[11] = ERL_DRV_TUPLE;
dataset[12] = 2; 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); driver_free(dataset);
return 0; return 0;
} }
@@ -301,7 +306,13 @@ static inline int output_ok(sqlite3_drv_t *drv) {
ERL_DRV_ATOM, drv->atom_ok, ERL_DRV_ATOM, drv->atom_ok,
ERL_DRV_TUPLE, 2 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) { 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; (async_sqlite3_command *) thread_data;
sqlite3_drv_t *drv = async_command->driver_data; sqlite3_drv_t *drv = async_command->driver_data;
int res = erl_drv_output_term(driver_mk_port(drv->port), 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->dataset,
async_command->term_count); async_command->term_count);
(void) res; // suppress unused warning
if (res != 1) { if (res != 1) {
LOG_DEBUG("driver_output_term returned %d\n", res); LOG_DEBUG("driver_output_term returned %d\n", res);
#ifdef DEBUG #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[3] = drv->prepared_count - 1;
spec[4] = ERL_DRV_TUPLE; spec[4] = ERL_DRV_TUPLE;
spec[5] = 2; 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) { 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); EXTEND_DATASET_DIRECT(2);
append_to_dataset(2, dataset, term_count, ERL_DRV_TUPLE, (ErlDrvTermData) 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); free_ptr_list(ptrs, driver_free_fun);
driver_free(dataset); driver_free(dataset);
return 0; 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_ATOM, drv->atom_unknown_cmd,
ERL_DRV_TUPLE, 4 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) { static inline ptr_list *add_to_ptr_list(ptr_list *list, void *value_ptr) {

View File

@@ -19,6 +19,17 @@
#error "SQLite3 of version 3.6.1 minumum required" #error "SQLite3 of version 3.6.1 minumum required"
#endif #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) #if defined(_MSC_VER)
#pragma warning(disable: 4201) #pragma warning(disable: 4201)
#pragma warning(disable: 4127) #pragma warning(disable: 4127)