(libretro-db) Style nits

This commit is contained in:
twinaphex 2015-09-17 07:09:31 +02:00
parent 7e3a83fbab
commit aa1405fab9
3 changed files with 45 additions and 48 deletions

View File

@ -9,8 +9,7 @@ static void *NIL_NODE = &NIL_NODE;
static struct bintree_node *new_nil_node(struct bintree_node *parent); static struct bintree_node *new_nil_node(struct bintree_node *parent);
void bintree_new(struct bintree *t, bintree_cmp_func cmp, void bintree_new(struct bintree *t, bintree_cmp_func cmp, void *ctx)
void *ctx)
{ {
t->root = new_nil_node(NULL); t->root = new_nil_node(NULL);
t->cmp = cmp; t->cmp = cmp;
@ -35,8 +34,7 @@ static INLINE int is_nil(const struct bintree_node *node)
return (node == NULL) || (node->value == NIL_NODE); return (node == NULL) || (node->value == NIL_NODE);
} }
static int insert(struct bintree *t, struct bintree_node *root, static int insert(struct bintree *t, struct bintree_node *root, void *value)
void *value)
{ {
int cmp_res = 0; int cmp_res = 0;

View File

@ -506,6 +506,7 @@ int libretrodb_create_index(libretrodb_t *db,
nictx.idx = &idx; nictx.idx = &idx;
bintree_iterate(&tree, node_iter, &nictx); bintree_iterate(&tree, node_iter, &nictx);
bintree_free(&tree); bintree_free(&tree);
clean: clean:
rmsgpack_dom_value_free(&item); rmsgpack_dom_value_free(&item);
if (buff) if (buff)

View File

@ -370,7 +370,7 @@ static struct rmsgpack_dom_value all_map(struct rmsgpack_dom_value input,
if (arg.type != AT_VALUE) if (arg.type != AT_VALUE)
{ {
res.val.bool_ = 0; res.val.bool_ = 0;
goto clean; return res;
} }
value = rmsgpack_dom_value_map_value(&input, &arg.value); value = rmsgpack_dom_value_map_value(&input, &arg.value);
if (!value) /* All missing fields are nil */ if (!value) /* All missing fields are nil */
@ -390,7 +390,7 @@ static struct rmsgpack_dom_value all_map(struct rmsgpack_dom_value input,
if (!res.val.bool_) if (!res.val.bool_)
break; break;
} }
clean:
return res; return res;
} }
@ -576,26 +576,24 @@ static struct buffer get_ident(struct buffer buff,
{ {
char c = '\0'; char c = '\0';
if (is_eot(buff)) if (is_eot(buff))
{ {
raise_unexpected_eof(buff.offset, error); raise_unexpected_eof(buff.offset, error);
return buff; return buff;
} }
*ident = buff.data + buff.offset; *ident = buff.data + buff.offset;
*len = 0; *len = 0;
peek_char(buff, &c, error); peek_char(buff, &c, error);
if (*error) if (*error || !isalpha(c))
goto clean; return buff;
if (!isalpha(c))
return buff;
buff.offset++; buff.offset++;
*len = *len + 1; *len = *len + 1;
peek_char(buff, &c, error); peek_char(buff, &c, error);
while (!*error) while (!*error)
{ {
if (!(isalpha(c) || isdigit(c) || c == '_')) if (!(isalpha(c) || isdigit(c) || c == '_'))
break; break;
@ -604,8 +602,7 @@ static struct buffer get_ident(struct buffer buff,
peek_char(buff, &c, error); peek_char(buff, &c, error);
} }
clean: return buff;
return buff;
} }
static struct buffer parse_method_call(struct buffer buff, static struct buffer parse_method_call(struct buffer buff,
@ -622,12 +619,12 @@ static struct buffer parse_method_call(struct buffer buff,
buff = get_ident(buff, &func_name, &func_name_len, error); buff = get_ident(buff, &func_name, &func_name_len, error);
if (*error) if (*error)
goto clean; goto error;
buff = chomp(buff); buff = chomp(buff);
buff = expect_char(buff, '(', error); buff = expect_char(buff, '(', error);
if (*error) if (*error)
goto clean; goto error;
while (rf->name) while (rf->name)
{ {
@ -643,7 +640,7 @@ static struct buffer parse_method_call(struct buffer buff,
{ {
raise_unknown_function(buff.offset, func_name, raise_unknown_function(buff.offset, func_name,
func_name_len, error); func_name_len, error);
goto clean; goto error;
} }
buff = chomp(buff); buff = chomp(buff);
@ -652,13 +649,13 @@ static struct buffer parse_method_call(struct buffer buff,
if (argi >= MAX_ARGS) if (argi >= MAX_ARGS)
{ {
raise_too_many_arguments(error); raise_too_many_arguments(error);
goto clean; goto error;
} }
buff = parse_argument(buff, &args[argi], error); buff = parse_argument(buff, &args[argi], error);
if (*error) if (*error)
goto clean; goto error;
argi++; argi++;
buff = chomp(buff); buff = chomp(buff);
@ -674,7 +671,7 @@ static struct buffer parse_method_call(struct buffer buff,
buff = expect_char(buff, ')', error); buff = expect_char(buff, ')', error);
if (*error) if (*error)
goto clean; goto error;
invocation->argc = argi; invocation->argc = argi;
invocation->argv = (struct argument*) invocation->argv = (struct argument*)
@ -683,16 +680,16 @@ static struct buffer parse_method_call(struct buffer buff,
if (!invocation->argv) if (!invocation->argv)
{ {
raise_enomem(error); raise_enomem(error);
goto clean; goto error;
} }
memcpy(invocation->argv, args, memcpy(invocation->argv, args,
sizeof(struct argument) * argi); sizeof(struct argument) * argi);
goto success; return buff;
clean:
error:
for (i = 0; i < argi; i++) for (i = 0; i < argi; i++)
argument_free(&args[i]); argument_free(&args[i]);
success:
return buff; return buff;
} }
@ -711,7 +708,7 @@ static struct buffer parse_table(struct buffer buff,
buff = expect_char(buff, '{', error); buff = expect_char(buff, '{', error);
if (*error) if (*error)
goto clean; goto error;
buff = chomp(buff); buff = chomp(buff);
@ -720,7 +717,7 @@ static struct buffer parse_table(struct buffer buff,
if (argi >= MAX_ARGS) if (argi >= MAX_ARGS)
{ {
raise_too_many_arguments(error); raise_too_many_arguments(error);
goto clean; goto error;
} }
if (isalpha(buff.data[buff.offset])) if (isalpha(buff.data[buff.offset]))
@ -737,7 +734,7 @@ static struct buffer parse_table(struct buffer buff,
); );
if (!args[argi].value.val.string.buff) if (!args[argi].value.val.string.buff)
goto clean; goto error;
strncpy( strncpy(
args[argi].value.val.string.buff, args[argi].value.val.string.buff,
@ -750,7 +747,7 @@ static struct buffer parse_table(struct buffer buff,
buff = parse_string(buff, &args[argi].value, error); buff = parse_string(buff, &args[argi].value, error);
if (*error) if (*error)
goto clean; goto error;
args[argi].type = AT_VALUE; args[argi].type = AT_VALUE;
buff = chomp(buff); buff = chomp(buff);
@ -758,20 +755,20 @@ static struct buffer parse_table(struct buffer buff,
buff = expect_char(buff, ':', error); buff = expect_char(buff, ':', error);
if (*error) if (*error)
goto clean; goto error;
buff = chomp(buff); buff = chomp(buff);
if (argi >= MAX_ARGS) if (argi >= MAX_ARGS)
{ {
raise_too_many_arguments(error); raise_too_many_arguments(error);
goto clean; goto error;
} }
buff = parse_argument(buff, &args[argi], error); buff = parse_argument(buff, &args[argi], error);
if (*error) if (*error)
goto clean; goto error;
argi++; argi++;
buff = chomp(buff); buff = chomp(buff);
buff = expect_char(buff, ',', error); buff = expect_char(buff, ',', error);
@ -787,7 +784,7 @@ static struct buffer parse_table(struct buffer buff,
buff = expect_char(buff, '}', error); buff = expect_char(buff, '}', error);
if (*error) if (*error)
goto clean; goto error;
invocation->func = all_map; invocation->func = all_map;
invocation->argc = argi; invocation->argc = argi;
@ -797,16 +794,16 @@ static struct buffer parse_table(struct buffer buff,
if (!invocation->argv) if (!invocation->argv)
{ {
raise_enomem(error); raise_enomem(error);
goto clean; goto error;
} }
memcpy(invocation->argv, args, memcpy(invocation->argv, args,
sizeof(struct argument) * argi); sizeof(struct argument) * argi);
goto success; return buff;
clean:
error:
for (i = 0; i < argi; i++) for (i = 0; i < argi; i++)
argument_free(&args[i]); argument_free(&args[i]);
success:
return buff; return buff;
} }
@ -862,7 +859,7 @@ void *libretrodb_query_compile(libretrodb_t *db,
struct query *q = (struct query*)malloc(sizeof(struct query)); struct query *q = (struct query*)malloc(sizeof(struct query));
if (!q) if (!q)
goto clean; goto error;
memset(q, 0, sizeof(struct query)); memset(q, 0, sizeof(struct query));
@ -878,25 +875,26 @@ void *libretrodb_query_compile(libretrodb_t *db,
{ {
buff = parse_table(buff, &q->root, error); buff = parse_table(buff, &q->root, error);
if (*error) if (*error)
goto clean; goto error;
} }
else if (isalpha(buff.data[buff.offset])) else if (isalpha(buff.data[buff.offset]))
buff = parse_method_call(buff, &q->root, error); buff = parse_method_call(buff, &q->root, error);
buff = expect_eof(buff, error); buff = expect_eof(buff, error);
if (*error) if (*error)
goto clean; goto error;
if (!q->root.func) if (!q->root.func)
{ {
raise_unexpected_eof(buff.offset, error); raise_unexpected_eof(buff.offset, error);
return NULL; return NULL;
} }
goto success;
clean: return q;
error:
if (q) if (q)
libretrodb_query_free(q); libretrodb_query_free(q);
success:
return q; return q;
} }