Update SDB with latest cleanups in sync with r2

This commit is contained in:
pancake 2021-05-30 23:04:09 +02:00 committed by GitHub
parent 02b6d5d4f0
commit dac25ce8de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 22 deletions

View File

@ -32,7 +32,6 @@ static StrBuf* strbuf_append(StrBuf *sb, const char *str, const int nl) {
if (!b) {
return NULL;
}
// free (sb->buf);
sb->buf = b;
sb->size = newsize;
}
@ -135,10 +134,9 @@ static bool foreach_list_cb(void *user, const char *k, const char *v) {
return true;
}
static void walk_namespace (StrBuf *sb, char *root, int left, char *p, SdbNs *ns, int encode) {
static void walk_namespace(StrBuf *sb, char *root, int left, char *p, SdbNs *ns, int encode) {
int len;
SdbListIter *it;
char *_out, *out = sb->buf;
SdbNs *n;
ForeachListUser user = { sb, encode, root };
char *roote = root + strlen (root);
@ -156,10 +154,8 @@ static void walk_namespace (StrBuf *sb, char *root, int left, char *p, SdbNs *ns
memcpy (p + 1, n->name, len + 1);
left -= len + 2;
}
_out = out;
walk_namespace (sb, root, left,
roote + len + 1, n, encode);
out = _out;
}
}
@ -168,13 +164,12 @@ SDB_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) {
const char *p, *q, *val = NULL;
char *eq, *tmp, *json, *next, *quot, *slash, *res,
*cmd, *newcmd = NULL, *original_cmd = NULL;
StrBuf *out;
Sdb *s = r;
ut64 n;
if (!s || (!_cmd && !buf)) {
return NULL;
}
out = strbuf_new ();
StrBuf *out = strbuf_new ();
if ((int)len < 1 || !buf) {
bufset = 1;
buf = malloc ((len = 64));
@ -838,10 +833,10 @@ fail:
return res;
}
SDB_API int sdb_query (Sdb *s, const char *cmd) {
char buf[1024], *out;
int must_save = ((*cmd=='~') || strchr (cmd, '='));
out = sdb_querys (s, buf, sizeof (buf) - 1, cmd);
SDB_API int sdb_query(Sdb *s, const char *cmd) {
char buf[1024];
int must_save = ((*cmd == '~') || strchr (cmd, '='));
char *out = sdb_querys (s, buf, sizeof (buf) - 1, cmd);
if (out) {
if (*out) {
puts (out);
@ -853,7 +848,7 @@ SDB_API int sdb_query (Sdb *s, const char *cmd) {
return must_save;
}
SDB_API int sdb_query_lines (Sdb *s, const char *cmd) {
SDB_API int sdb_query_lines(Sdb *s, const char *cmd) {
char *o, *p, *op;
if (!s || !cmd) {
return 0;
@ -878,27 +873,25 @@ SDB_API int sdb_query_lines (Sdb *s, const char *cmd) {
}
static char *slurp(const char *file) {
int ret, fd;
char *text;
long sz;
if (!file || !*file)
if (!file || !*file) {
return NULL;
fd = open (file, O_RDONLY);
}
int fd = open (file, O_RDONLY);
if (fd == -1) {
return NULL;
}
sz = lseek (fd, 0, SEEK_END);
if (sz < 0){
long sz = lseek (fd, 0, SEEK_END);
if (sz < 0) {
close (fd);
return NULL;
}
lseek (fd, 0, SEEK_SET);
text = malloc (sz + 1);
char *text = malloc (sz + 1);
if (!text) {
close (fd);
return NULL;
}
ret = read (fd, text, sz);
int ret = read (fd, text, sz);
if (ret != sz) {
free (text);
text = NULL;

View File

@ -662,7 +662,6 @@ SDB_API int sdb_set(Sdb* s, const char *key, const char *val, ut32 cas) {
static bool sdb_foreach_list_cb(void *user, const char *k, const char *v) {
SdbList *list = (SdbList *)user;
// list->free = (SdbListFree)sdbkv_free;
SdbKv *kv = R_NEW0 (SdbKv);
/* seems like some k/v are constructed in the stack and cant be used after returning */
kv->base.key = strdup (k);