Fixed most remaining warnings
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
#include "sqlite3_drv.h"
|
#include "sqlite3_drv.h"
|
||||||
#include "ei.h"
|
|
||||||
#include "assert.h"
|
|
||||||
|
|
||||||
// MSVC needs "__inline" instead of "inline" in C-source files.
|
// MSVC needs "__inline" instead of "inline" in C-source files.
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
@@ -27,14 +25,16 @@ static ErlDrvEntry basic_driver_entry = {
|
|||||||
ERL_DRV_EXTENDED_MARKER, /* ERL_DRV_EXTENDED_MARKER */
|
ERL_DRV_EXTENDED_MARKER, /* ERL_DRV_EXTENDED_MARKER */
|
||||||
ERL_DRV_EXTENDED_MAJOR_VERSION, /* ERL_DRV_EXTENDED_MAJOR_VERSION */
|
ERL_DRV_EXTENDED_MAJOR_VERSION, /* ERL_DRV_EXTENDED_MAJOR_VERSION */
|
||||||
ERL_DRV_EXTENDED_MAJOR_VERSION, /* ERL_DRV_EXTENDED_MINOR_VERSION */
|
ERL_DRV_EXTENDED_MAJOR_VERSION, /* ERL_DRV_EXTENDED_MINOR_VERSION */
|
||||||
ERL_DRV_FLAG_USE_PORT_LOCKING /* ERL_DRV_FLAGs */
|
ERL_DRV_FLAG_USE_PORT_LOCKING, /* ERL_DRV_FLAGs */
|
||||||
|
NULL /* handle2 */,
|
||||||
|
NULL /* process_exit */,
|
||||||
|
NULL /* stop_select */
|
||||||
};
|
};
|
||||||
|
|
||||||
DRIVER_INIT(basic_driver) {
|
DRIVER_INIT(basic_driver) {
|
||||||
return &basic_driver_entry;
|
return &basic_driver_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int print_dataset(ErlDrvTermData *dataset, int term_count);
|
|
||||||
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);
|
||||||
static inline void free_ptr_list(ptr_list *list, void(* free_head)(void *));
|
static inline void free_ptr_list(ptr_list *list, void(* free_head)(void *));
|
||||||
static inline int max(int a, int b);
|
static inline int max(int a, int b);
|
||||||
@@ -103,7 +103,8 @@ static void stop(ErlDrvData handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle input from Erlang VM
|
// Handle input from Erlang VM
|
||||||
static int control(ErlDrvData drv_data, unsigned int command, char *buf,
|
static int control(
|
||||||
|
ErlDrvData drv_data, unsigned int command, char *buf,
|
||||||
int len, char **rbuf, int rlen) {
|
int len, char **rbuf, int rlen) {
|
||||||
sqlite3_drv_t* driver_data = (sqlite3_drv_t*) drv_data;
|
sqlite3_drv_t* driver_data = (sqlite3_drv_t*) drv_data;
|
||||||
switch (command) {
|
switch (command) {
|
||||||
@@ -151,7 +152,8 @@ static inline int output_db_error(sqlite3_drv_t *drv) {
|
|||||||
return output_error(drv, sqlite3_errcode(drv->db), sqlite3_errmsg(drv->db));
|
return output_error(drv, sqlite3_errcode(drv->db), sqlite3_errmsg(drv->db));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int sql_exec_statement(sqlite3_drv_t *drv, sqlite3_stmt *statement) {
|
static inline int sql_exec_statement(
|
||||||
|
sqlite3_drv_t *drv, sqlite3_stmt *statement) {
|
||||||
async_sqlite3_command *async_command =
|
async_sqlite3_command *async_command =
|
||||||
(async_sqlite3_command *) calloc(1, sizeof(async_sqlite3_command));
|
(async_sqlite3_command *) calloc(1, sizeof(async_sqlite3_command));
|
||||||
async_command->driver_data = drv;
|
async_command->driver_data = drv;
|
||||||
@@ -377,7 +379,6 @@ static int sql_bind_and_exec(sqlite3_drv_t *drv, char *buffer, int buffer_size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void sql_free_async(void *_async_command) {
|
static void sql_free_async(void *_async_command) {
|
||||||
int i;
|
|
||||||
async_sqlite3_command *async_command =
|
async_sqlite3_command *async_command =
|
||||||
(async_sqlite3_command *) _async_command;
|
(async_sqlite3_command *) _async_command;
|
||||||
free(async_command->dataset);
|
free(async_command->dataset);
|
||||||
@@ -389,12 +390,6 @@ static void sql_free_async(void *_async_command) {
|
|||||||
free_ptr_list(async_command->binaries,
|
free_ptr_list(async_command->binaries,
|
||||||
(void (*)(void *)) &driver_free_binary);
|
(void (*)(void *)) &driver_free_binary);
|
||||||
|
|
||||||
// for (i = 0; i < async_command->binaries_count; i++) {
|
|
||||||
// driver_free_binary(async_command->binaries[i]);
|
|
||||||
// }
|
|
||||||
// if (async_command->binaries) {
|
|
||||||
// free(async_command->binaries);
|
|
||||||
// }
|
|
||||||
if (async_command->statement) {
|
if (async_command->statement) {
|
||||||
sqlite3_finalize(async_command->statement);
|
sqlite3_finalize(async_command->statement);
|
||||||
}
|
}
|
||||||
@@ -410,9 +405,7 @@ static void sql_exec_async(void *_async_command) {
|
|||||||
int row_count = async_command->row_count;
|
int row_count = async_command->row_count;
|
||||||
sqlite3_drv_t *drv = async_command->driver_data;
|
sqlite3_drv_t *drv = async_command->driver_data;
|
||||||
|
|
||||||
int result, next_row, column_count;
|
int next_row, column_count;
|
||||||
char *error = NULL;
|
|
||||||
char *rest = NULL;
|
|
||||||
sqlite3_stmt *statement = async_command->statement;
|
sqlite3_stmt *statement = async_command->statement;
|
||||||
|
|
||||||
ptr_list *ptrs = NULL;
|
ptr_list *ptrs = NULL;
|
||||||
@@ -634,6 +627,7 @@ static void ready_async(ErlDrvData drv_data, ErlDrvThreadData thread_data) {
|
|||||||
int res = driver_output_term(drv->port,
|
int res = driver_output_term(drv->port,
|
||||||
async_command->dataset,
|
async_command->dataset,
|
||||||
async_command->term_count);
|
async_command->term_count);
|
||||||
|
(void) res; // suppress unused warning
|
||||||
// fprintf(drv->log, "Total term count: %p %d, rows count: %d (%d)\n", async_command->statement, async_command->term_count, async_command->row_count, res);
|
// fprintf(drv->log, "Total term count: %p %d, rows count: %d (%d)\n", async_command->statement, async_command->term_count, async_command->row_count, res);
|
||||||
// fflush(drv->log);
|
// fflush(drv->log);
|
||||||
sql_free_async(async_command);
|
sql_free_async(async_command);
|
||||||
@@ -651,39 +645,6 @@ static int unknown(sqlite3_drv_t *drv, char *command, int command_size) {
|
|||||||
return driver_output_term(drv->port, spec, sizeof(spec) / sizeof(spec[0]));
|
return driver_output_term(drv->port, spec, sizeof(spec) / sizeof(spec[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int print_dataset(ErlDrvTermData *dataset, int term_count) {
|
|
||||||
ErlDrvTermData lastData = *dataset;
|
|
||||||
ErlDrvTermData newData;
|
|
||||||
int i;
|
|
||||||
printf("dataset (%d terms):\n", term_count);
|
|
||||||
for (i = 1; i < term_count; i++) {
|
|
||||||
dataset++;
|
|
||||||
newData = *dataset;
|
|
||||||
switch (lastData) {
|
|
||||||
case ERL_DRV_INT:
|
|
||||||
printf("int: %ld\n", (ErlDrvSInt) newData);
|
|
||||||
break;
|
|
||||||
case ERL_DRV_INT64:
|
|
||||||
printf("int64: %p:%lld\n", (void *) newData,
|
|
||||||
*(ErlDrvSInt64 *) newData);
|
|
||||||
break;
|
|
||||||
case ERL_DRV_FLOAT:
|
|
||||||
printf("int64: %p:%f\n", (void *) newData, *(double *) newData);
|
|
||||||
break;
|
|
||||||
// case ERL_DRV_TUPLE:
|
|
||||||
// printf("tuple of size %d\n", (int) newData);
|
|
||||||
// break;
|
|
||||||
// case ERL_DRV_LIST:
|
|
||||||
// printf("list of length %d\n", (int) newData);
|
|
||||||
// break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
lastData = newData;
|
|
||||||
}
|
|
||||||
return 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) {
|
||||||
ptr_list* new_node = malloc(sizeof(ptr_list));
|
ptr_list* new_node = malloc(sizeof(ptr_list));
|
||||||
new_node->head = value_ptr;
|
new_node->head = value_ptr;
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#include <erl_driver.h>
|
#include <erl_driver.h>
|
||||||
|
#include <erl_interface.h>
|
||||||
#include <ei.h>
|
#include <ei.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
#include <erl_interface.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#if SQLITE_VERSION_NUMBER < 3006001
|
#if SQLITE_VERSION_NUMBER < 3006001
|
||||||
#error "SQLite3 of version 3.6.1 minumum required"
|
#error "SQLite3 of version 3.6.1 minumum required"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
% -*- mode: erlang -*-
|
% -*- mode: erlang -*-
|
||||||
{erl_opts, [debug_info]}. %% required for dialyzer
|
{erl_opts, [debug_info]}. %% required for dialyzer
|
||||||
{port_envs, [{"DRV_LDFLAGS", "$DRV_LDFLAGS -lsqlite3"}]}.
|
{port_envs, [{"DRV_LDFLAGS", "$DRV_LDFLAGS -lsqlite3"},
|
||||||
|
{"DRV_CFLAGS", "$DRV_CFLAGS -Wall -Wextra -Wno-unused-parameter"}]}.
|
||||||
{cover_enabled, true}.
|
{cover_enabled, true}.
|
||||||
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
|
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
|
||||||
{dialyzer_opts, [{plt, "dialyzer/sqlite3.plt"}]}.
|
{dialyzer_opts, [{plt, "dialyzer/sqlite3.plt"}]}.
|
||||||
|
|||||||
Reference in New Issue
Block a user