radareorg / sdb

Simple and fast string based key-value database with support for arrays and json
https://www.radare.org/
MIT License
217 stars 62 forks source link

Sdbkv refactor #162

Closed ret2libc closed 6 years ago

ret2libc commented 6 years ago

This PR is based on https://github.com/radare/sdb/pull/158 .

The only difference is the last commits. The commit introduces helper macros in the sdbht.h file to access SdbKv->key/value/key_len/value_len since they are fields of the "base structure" HtKv. In another PR i'm going to change those fields, so I want to introduce these helpers to make those change easier.

ret2libc commented 6 years ago

I intend to sync radare2 after merging this commit, so that in next PRs I can change

struct SdbKv {
    //sub of HtKv so we can cast safely
    char *key;
    char *value;
    ut32 key_len;
    ut32 value_len;
    ut32 cas;
    ut64 expire;
};

to

typedef struct sdb_kv {
    //sub of HtKv so we can cast safely
    HtKv base;
    ut32 cas;
    ut64 expire;
} SdbKv;

easily, without rewriting everything. Also, this will be helpful because key/value are both char* in SdbKv, but not in HtKv, so a cast will be needed.

radare commented 6 years ago

We probably dont need those macros at all

On 4 Oct 2018, at 12:05, Riccardo Schirone notifications@github.com wrote:

@ret2libc commented on this pull request.

In src/sdbht.h:

@@ -14,6 +14,11 @@ typedef struct sdb_kv { ut64 expire; } SdbKv;

+#define SDBKV_KEY(kv) ((kv)->key) @radare Do you prefer static inline functions instead of these macros?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ret2libc commented 6 years ago

We probably dont need those macros at all

See this comment https://github.com/radare/sdb/pull/162#issuecomment-426960357