(libretro-db/query.c) Cleanup

This commit is contained in:
twinaphex 2016-09-22 20:48:49 +02:00
parent 1c1cac328d
commit 70d4da3e32

View File

@ -973,45 +973,44 @@ void libretrodb_query_free(void *q)
} }
void *libretrodb_query_compile(libretrodb_t *db, void *libretrodb_query_compile(libretrodb_t *db,
const char *query, size_t buff_len, const char **error) const char *query, size_t buff_len, const char **error_string)
{ {
struct buffer buff; struct buffer buff;
struct query *q = (struct query*)calloc(1, sizeof(*q)); struct query *q = (struct query*)calloc(1, sizeof(*q));
if (!q) if (!q)
goto clean; goto error;
q->ref_count = 1; q->ref_count = 1;
buff.data = query; buff.data = query;
buff.len = buff_len; buff.len = buff_len;
buff.offset = 0; buff.offset = 0;
*error = NULL; *error_string = NULL;
buff = query_chomp(buff); buff = query_chomp(buff);
if (query_peek(buff, "{")) if (query_peek(buff, "{"))
{ {
buff = query_parse_table(buff, &q->root, error); buff = query_parse_table(buff, &q->root, error_string);
if (*error) if (*error_string)
goto clean; goto error;
} }
else if (isalpha((int)buff.data[buff.offset])) else if (isalpha((int)buff.data[buff.offset]))
buff = query_parse_method_call(buff, &q->root, error); buff = query_parse_method_call(buff, &q->root, error_string);
buff = query_expect_eof(buff, error); buff = query_expect_eof(buff, error_string);
if (*error) if (*error_string)
goto clean; goto error;
if (!q->root.func) if (!q->root.func)
{ {
query_raise_unexpected_eof(buff.offset, error); query_raise_unexpected_eof(buff.offset, error_string);
libretrodb_query_free(q); goto error;
return NULL;
} }
return q; return q;
clean: error:
if (q) if (q)
libretrodb_query_free(q); libretrodb_query_free(q);
return NULL; return NULL;