Skip to content

Commit

Permalink
Use single codebase for all Erlang versions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyr committed Oct 12, 2014
1 parent ed2ae9d commit d070190
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -3,3 +3,5 @@ script: "make test"
otp_release:
- 17.1
- R16B03-1
- R15B03
- R14B04
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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

Expand Down
50 changes: 41 additions & 9 deletions c_src/sqlite3_drv.c
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions c_src/sqlite3_drv.h
Expand Up @@ -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)
Expand Down

0 comments on commit d070190

Please sign in to comment.