Fixed indentation
This commit is contained in:
@@ -430,9 +430,6 @@ do_close(ErlNifEnv *env, esqlite_connection *conn, const ERL_NIF_TERM arg)
|
||||
static ERL_NIF_TERM
|
||||
evaluate_command(esqlite_command *cmd, esqlite_connection *conn)
|
||||
{
|
||||
if(!conn->db)
|
||||
make_error_tuple(cmd->env, "database_not_open");
|
||||
|
||||
switch(cmd->type) {
|
||||
case cmd_open:
|
||||
return do_open(cmd->env, conn, cmd->arg);
|
||||
@@ -570,13 +567,10 @@ esqlite_exec(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
|
||||
if(argc != 4)
|
||||
return enif_make_badarg(env);
|
||||
|
||||
if(!enif_get_resource(env, argv[0], esqlite_connection_type, (void **) &db))
|
||||
return enif_make_badarg(env);
|
||||
|
||||
if(!enif_is_ref(env, argv[1]))
|
||||
return make_error_tuple(env, "invalid_ref");
|
||||
|
||||
if(!enif_get_local_pid(env, argv[2], &pid))
|
||||
return make_error_tuple(env, "invalid_pid");
|
||||
|
||||
@@ -664,10 +658,8 @@ esqlite_bind(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
return make_error_tuple(env, "no_connection");
|
||||
if(!stmt->connection->commands)
|
||||
return make_error_tuple(env, "no_command_queue");
|
||||
|
||||
if(!queue_push(stmt->connection->commands, cmd))
|
||||
return make_error_tuple(env, "command_push_failed");
|
||||
|
||||
return make_atom(env, "ok");
|
||||
}
|
||||
|
||||
@@ -689,7 +681,6 @@ esqlite_step(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
return make_error_tuple(env, "invalid_ref");
|
||||
if(!enif_get_local_pid(env, argv[2], &pid))
|
||||
return make_error_tuple(env, "invalid_pid");
|
||||
|
||||
if(!stmt->statement)
|
||||
return make_error_tuple(env, "no_prepared_statement");
|
||||
|
||||
@@ -706,10 +697,8 @@ esqlite_step(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
return make_error_tuple(env, "no_connection");
|
||||
if(!stmt->connection->commands)
|
||||
return make_error_tuple(env, "no_command_queue");
|
||||
|
||||
if(!queue_push(stmt->connection->commands, cmd))
|
||||
return make_error_tuple(env, "command_push_failed");
|
||||
|
||||
return make_atom(env, "ok");
|
||||
}
|
||||
|
||||
@@ -748,10 +737,8 @@ esqlite_column_names(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
return make_error_tuple(env, "no_connection");
|
||||
if(!stmt->connection->commands)
|
||||
return make_error_tuple(env, "no_command_queue");
|
||||
|
||||
if(!queue_push(stmt->connection->commands, cmd))
|
||||
return make_error_tuple(env, "command_push_failed");
|
||||
|
||||
return make_atom(env, "ok");
|
||||
}
|
||||
|
||||
@@ -767,10 +754,8 @@ esqlite_close(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
|
||||
if(!enif_get_resource(env, argv[0], esqlite_connection_type, (void **) &conn))
|
||||
return enif_make_badarg(env);
|
||||
|
||||
if(!enif_is_ref(env, argv[1]))
|
||||
return make_error_tuple(env, "invalid_ref");
|
||||
|
||||
if(!enif_get_local_pid(env, argv[2], &pid))
|
||||
return make_error_tuple(env, "invalid_pid");
|
||||
|
||||
@@ -778,8 +763,6 @@ esqlite_close(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
if(!cmd)
|
||||
return make_error_tuple(env, "command_create_failed");
|
||||
|
||||
/* Push the close command on the queue
|
||||
*/
|
||||
cmd->type = cmd_close;
|
||||
cmd->ref = enif_make_copy(cmd->env, argv[1]);
|
||||
cmd->pid = pid;
|
||||
@@ -818,7 +801,7 @@ static ErlNifFunc nif_funcs[] = {
|
||||
{"exec", 4, esqlite_exec},
|
||||
{"prepare", 4, esqlite_prepare},
|
||||
{"step", 3, esqlite_step},
|
||||
// {"esqlite_bind", 3, esqlite_bind_named},
|
||||
// TODO: {"esqlite_bind", 3, esqlite_bind_named},
|
||||
{"bind", 4, esqlite_bind},
|
||||
{"column_names", 3, esqlite_column_names},
|
||||
{"close", 3, esqlite_close}
|
||||
|
||||
@@ -32,8 +32,7 @@ queue_create()
|
||||
queue *ret;
|
||||
|
||||
ret = (queue *) enif_alloc(sizeof(struct queue_t));
|
||||
if(ret == NULL)
|
||||
goto error;
|
||||
if(ret == NULL) goto error;
|
||||
|
||||
ret->lock = NULL;
|
||||
ret->cond = NULL;
|
||||
@@ -43,12 +42,10 @@ queue_create()
|
||||
ret->length = 0;
|
||||
|
||||
ret->lock = enif_mutex_create("queue_lock");
|
||||
if(ret->lock == NULL)
|
||||
goto error;
|
||||
if(ret->lock == NULL) goto error;
|
||||
|
||||
ret->cond = enif_cond_create("queue_cond");
|
||||
if(ret->cond == NULL)
|
||||
goto error;
|
||||
if(ret->cond == NULL) goto error;
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -114,16 +111,12 @@ queue_push(queue *queue, void *item)
|
||||
assert(queue->length >= 0 && "Invalid queue size at push");
|
||||
|
||||
if(queue->tail != NULL)
|
||||
{
|
||||
queue->tail->next = entry;
|
||||
}
|
||||
|
||||
queue->tail = entry;
|
||||
|
||||
if(queue->head == NULL)
|
||||
{
|
||||
queue->head = queue->tail;
|
||||
}
|
||||
|
||||
queue->length += 1;
|
||||
|
||||
@@ -144,9 +137,7 @@ queue_pop(queue *queue)
|
||||
/* Wait for an item to become available.
|
||||
*/
|
||||
while(queue->head == NULL)
|
||||
{
|
||||
enif_cond_wait(queue->cond, queue->lock);
|
||||
}
|
||||
|
||||
assert(queue->length >= 0 && "Invalid queue size at pop.");
|
||||
|
||||
@@ -157,8 +148,7 @@ queue_pop(queue *queue)
|
||||
queue->head = entry->next;
|
||||
entry->next = NULL;
|
||||
|
||||
if(queue->head == NULL)
|
||||
{
|
||||
if(queue->head == NULL) {
|
||||
assert(queue->tail == entry && "Invalid queue state: Bad tail.");
|
||||
queue->tail = NULL;
|
||||
}
|
||||
@@ -194,9 +184,7 @@ queue_receive(queue *queue)
|
||||
/* Wait for an item to become available.
|
||||
*/
|
||||
while(queue->message == NULL)
|
||||
{
|
||||
enif_cond_wait(queue->cond, queue->lock);
|
||||
}
|
||||
|
||||
item = queue->message;
|
||||
queue->message = NULL;
|
||||
|
||||
Reference in New Issue
Block a user