Avoid sdb double headers (#17249) ##build

* Avoid duplication of SDB headers in libr/include

SDB is an external project and as such it should live in shlr. However,
for simplicity in dealing with the include flags, the SDB headers were
copied in libr/include as well. This patch just keeps the SDB files
confined in shlr/sdb and make sure various r_* libs use the headers from
there.

* Fix pkgconfig file generation
This commit is contained in:
Riccardo Schirone 2020-07-21 10:28:43 +02:00 committed by GitHub
parent 9869a4d8f9
commit 2d160f2509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
59 changed files with 227 additions and 1235 deletions

View File

@ -149,7 +149,7 @@ windist:
mkdir -p "${WINDIST}/include/libr/sdb"
mkdir -p "${WINDIST}/include/libr/r_util"
@echo "${C}[WINDIST] Copying development files${R}"
cp -f libr/include/sdb/*.h "${WINDIST}/include/libr/sdb/"
cp -f shlr/sdb/src/*.h "${WINDIST}/include/libr/sdb/"
cp -f libr/include/r_util/*.h "${WINDIST}/include/libr/r_util/"
cp -f libr/include/*.h "${WINDIST}/include/libr"
#mkdir -p "${WINDIST}/include/libr/sflib"

View File

@ -7,6 +7,8 @@ CFLAGS+=-pie
endif
CFLAGS+=-I$(LTOP)/include
include ../../shlr/sdb.mk
ifeq (${COMPILER},emscripten)
LINK+=$(SHLR)/libr_shlr.a
LINK+=$(SHLR)/sdb/src/libsdb.a

View File

@ -183,7 +183,7 @@ install-includes:
done ; \
done)
${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/libr/sdb"
(cd include/sdb && for FILE in * ; do \
(cd ../shlr/sdb/src && for FILE in *.h ; do \
${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/libr/sdb/$$FILE" ; \
done)
${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/libr/r_util"
@ -200,6 +200,7 @@ symstall install-symlink:
"${DESTDIR}${LIBDIR}/pkgconfig" \
"${DESTDIR}${LIBDIR}/radare2/${VERSION}" ; \
rm -rf "${DESTDIR}${INCLUDEDIR}/libr" && ln -fs "${PWD}/include" "${DESTDIR}${INCLUDEDIR}/libr" ; \
rm -rf "${DESTDIR}${INCLUDEDIR}/libr/sdb" && ln -fs "${PWD}/../shlr/sdb/src" "${DESTDIR}${INCLUDEDIR}/libr/sdb" ; \
$(MAKE) install-pkgconfig-symlink ; \
$(foreach lib,${LIBS}, \
ln -fs "${PWD}/$(lib)/libr_$(lib).${EXT_SO}" \

View File

@ -1,7 +1,7 @@
/* radare - LGPL - Copyright 2019-2020 - pancake, thestr4ng3r */
#include <r_anal.h>
#include <sdb/ht_uu.h>
#include <ht_uu.h>
#include <assert.h>

View File

@ -2,7 +2,7 @@
#include <r_anal.h>
#include <string.h>
#include "sdb/sdb.h"
#include <sdb.h>
static char *is_type(char *type) {
char *name = NULL;

View File

@ -1,5 +1,5 @@
#include <r_anal.h>
#include "sdb/sdb.h"
#include <sdb.h>
#include <string.h>
#include <r_bin_dwarf.h>

View File

@ -224,7 +224,6 @@ r_asm = library('r_asm', r_asm_sources,
r_flag_dep,
r_socket_dep,
capstone_dep,
spp_dep,
java_dep
],
install: true,

View File

@ -7,7 +7,7 @@
#include <r_util.h>
#include <r_lib.h>
#include <r_bin.h>
#include <sdb/ht_up.h>
#include <ht_up.h>
#define COFF_IS_BIG_ENDIAN 1
#define COFF_IS_LITTLE_ENDIAN 0

View File

@ -8,7 +8,7 @@
#include <r_util.h>
#include "pe.h"
#include <time.h>
#include <sdb/ht_uu.h>
#include <ht_uu.h>
#define PE_IMAGE_FILE_MACHINE_RPI2 452
#define MAX_METADATA_STRING_LENGTH 256

View File

@ -4,7 +4,7 @@
#include <r_util.h>
#include <r_lib.h>
#include <r_bin.h>
#include <sdb/ht_uu.h>
#include <ht_uu.h>
#include "coff/coff.h"

View File

@ -9,7 +9,7 @@
#include <r_cons.h>
#include "../i/private.h"
#include "elf/elf.h"
#include <sdb/ht_uu.h>
#include <ht_uu.h>
static RBinInfo* info(RBinFile *bf);

View File

@ -8,7 +8,7 @@
#include "../i/private.h"
#include "mach0/mach0.h"
#include "objc/mach0_classes.h"
#include <sdb/ht_uu.h>
#include <ht_uu.h>
// wip settings

View File

@ -4,7 +4,7 @@
#include <r_util.h>
#include <r_lib.h>
#include <r_bin.h>
#include <sdb/ht_uu.h>
#include <ht_uu.h>
#include "../i/private.h"
#include "mach0/coresymbolication.h"

View File

@ -5,7 +5,7 @@
#include <r_flag.h>
#include <r_core.h>
#include <r_bin.h>
#include <sdb/ht_uu.h>
#include <ht_uu.h>
#include <string.h>

View File

@ -2,7 +2,7 @@
#include <r_core.h>
#include <r_debug.h>
#include <sdb/sdb.h>
#include <sdb.h>
#define TN_KEY_LEN 32
#define TN_KEY_FMT "%"PFMT64u
#ifndef SIGKILL

View File

@ -6,7 +6,7 @@
#include "r_core.h"
#include "r_util.h"
#include "r_types.h"
#include "sdb/sdb.h"
#include <sdb.h>
char *getcommapath(RCore *core);

View File

@ -1,6 +1,6 @@
/* radare - LGPL - Copyright 2010-2019 - pancake */
#include <sdb/ht_uu.h>
#include <ht_uu.h>
#include <r_core.h>
#include <r_hash.h>
#include "r_io.h"

View File

@ -4,7 +4,7 @@
#include "r_anal.h"
#include "r_cons.h"
#include "r_core.h"
#include "sdb/sdb.h"
#include <sdb.h>
static const char *help_msg_t[] = {
"Usage: t", "", "# cparse types commands",

View File

@ -100,7 +100,6 @@ r_core_deps = [
r_asm_dep,
r_bp_dep,
platform_deps,
spp_dep,
gdb_dep,
java_dep,
shell_parser_dep

View File

@ -15,7 +15,7 @@
#include <r_util.h>
#include <r_bind.h>
#include <r_syscall.h>
#include <sdb/set.h>
#include <set.h>
#include <r_flag.h>
#include <r_bin.h>

View File

@ -21,7 +21,7 @@ extern "C" {
#include <r_util/r_file.h>
#include <r_vector.h>
#include <sdb.h>
#include <sdb/ht_up.h>
#include <ht_up.h>
#include <stdio.h>
#include <sys/types.h>

View File

@ -7,7 +7,7 @@
extern "C" {
#endif
#include <sdb/ht_up.h>
#include <ht_up.h>
#include <r_vector.h>
typedef struct r_event_t {

View File

@ -2,7 +2,7 @@
#define R_STR_CONSTPOOL_H
#include <r_types.h>
#include <sdb/sdbht.h>
#include <sdbht.h>
#include <stdbool.h>

View File

@ -1 +0,0 @@
#include <sdb/sdb.h>

View File

@ -1,57 +0,0 @@
#ifndef BUFFER_H
#define BUFFER_H
#include "types.h"
typedef int (*BufferOp)(int, const char *, int);
typedef struct buffer {
char *x;
unsigned int p;
unsigned int n;
int fd;
BufferOp op;
} buffer;
#define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), (fd), (op) }
#define BUFFER_INSIZE 8192
#define BUFFER_OUTSIZE 8192
extern void buffer_init(buffer *,BufferOp,int,char *,unsigned int);
extern int buffer_flush(buffer *);
extern int buffer_put(buffer *,const char *,unsigned int);
extern int buffer_putalign(buffer *,const char *,unsigned int);
extern int buffer_putflush(buffer *,const char *,unsigned int);
#define buffer_PUTC(s,c) \
( ((s)->n != (s)->p) \
? ( (s)->x[(s)->p++] = (c), 0 ) \
: buffer_put((s),&(c),1) \
)
extern int buffer_get(buffer *,char *,unsigned int);
extern int buffer_bget(buffer *,char *,unsigned int);
extern int buffer_feed(buffer *);
extern char *buffer_peek(buffer *);
extern void buffer_seek(buffer *,unsigned int);
#define buffer_PEEK(s) ( (s)->x + (s)->n )
#define buffer_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) )
#define buffer_GETC(s,c) \
( ((s)->p > 0) \
? ( *(c) = (s)->x[(s)->n], buffer_SEEK((s),1), 1 ) \
: buffer_get((s),(c),1) \
)
extern int buffer_copy(buffer *,buffer *);
extern buffer *buffer_0;
extern buffer *buffer_0small;
extern buffer *buffer_1;
extern buffer *buffer_1small;
extern buffer *buffer_2;
#endif

View File

@ -1,39 +0,0 @@
/* Public domain. */
#ifndef CDB_H
#define CDB_H
#include <string.h>
#include "types.h"
#define KVLSZ 4
#define CDB_MAX_KEY 0xff
#define CDB_MAX_VALUE 0xffffff
#define CDB_HASHSTART 5381
struct cdb {
char *map; /* 0 if no map is available */
int fd; /* filedescriptor */
ut32 size; /* initialized if map is nonzero */
ut32 loop; /* number of hash slots searched under this key */
ut32 khash; /* initialized if loop is nonzero */
ut32 kpos; /* initialized if loop is nonzero */
ut32 hpos; /* initialized if loop is nonzero */
ut32 hslots; /* initialized if loop is nonzero */
ut32 dpos; /* initialized if cdb_findnext() returns 1 */
ut32 dlen; /* initialized if cdb_findnext() returns 1 */
};
/* TODO THIS MUST GTFO! */
bool cdb_getkvlen(struct cdb *db, ut32 *klen, ut32 *vlen, ut32 pos);
void cdb_free(struct cdb *);
bool cdb_init(struct cdb *, int fd);
void cdb_findstart(struct cdb *);
bool cdb_read(struct cdb *, char *, unsigned int, ut32);
int cdb_findnext(struct cdb *, ut32 u, const char *, ut32);
#define cdb_datapos(c) ((c)->dpos)
#define cdb_datalen(c) ((c)->dlen)
#endif

View File

@ -1,40 +0,0 @@
/* Public domain. */
#ifndef CDB_MAKE_H
#define CDB_MAKE_H
#include "buffer.h"
#include "types.h"
#define CDB_HPLIST 1000
struct cdb_hp { ut32 h; ut32 p; } ;
struct cdb_hplist {
struct cdb_hp hp[CDB_HPLIST];
struct cdb_hplist *next;
int num;
};
struct cdb_make {
char bspace[8192];
char final[1024];
ut32 count[256];
ut32 start[256];
struct cdb_hplist *head;
struct cdb_hp *split; /* includes space for hash */
struct cdb_hp *hash;
ut32 numentries;
ut32 memsize;
buffer b;
ut32 pos;
int fd;
};
extern int cdb_make_start(struct cdb_make *,int);
extern int cdb_make_addbegin(struct cdb_make *,unsigned int,unsigned int);
extern int cdb_make_addend(struct cdb_make *,unsigned int,unsigned int,ut32);
extern int cdb_make_add(struct cdb_make *,const char *,unsigned int,const char *,unsigned int);
extern int cdb_make_finish(struct cdb_make *);
#endif

View File

@ -1,16 +0,0 @@
#ifndef CONFIG_H
#define CONFIG_H
#define SDB_KEYSIZE 32
/* only available on linux, and some distros require -lrt */
#define USE_MONOTONIC_CLOCK 0
#if SDB_KEYSIZE == 32
#define SDB_KT ut32
#elif SDB_KEYSIZE == 64
#define SDB_KT ut64
#else
#error Invalid key size
#endif
#endif

View File

@ -1,50 +0,0 @@
#define MHTSZ 32
#define MHTNO 0
typedef ut64 dicti;
typedef struct {
dicti k;
dicti v;
void *u;
#if 0
// unaligned
// on 32bits
void *pad;
// on 64bits
void *pad;
#endif
} dictkv;
// 4 + 4 + 4 = 12 .. missing 4 more
// 8 + 8 + 4 = 20 .. missing 16, what about 32 ?
// 8 + 8 + 8 = 24 .. still not there, missing 8
// 4 + 4 + 8 = 16 .. lgtm
typedef void (*dict_freecb)(void *);
typedef int (*dictkv_cb)(dictkv *, void *);
typedef struct {
void **table; //[MHTSZ];
dict_freecb f;
ut32 size;
} dict;
typedef dict SdbMini;
SDB_API dict *dict_new(ut32 size, dict_freecb f);
SDB_API void dict_free(dict*);
SDB_API bool dict_init(dict *m, ut32, dict_freecb f);
SDB_API void dict_fini(dict *m);
SDB_API void dict_stats(dict *m);
SDB_API dicti dict_hash(const char *s);
SDB_API bool dict_set(dict *m, dicti k, dicti v, void *u);
SDB_API dictkv *dict_getr(dict *m, dicti k);
SDB_API dictkv *dict_getr(dict *m, dicti k);
SDB_API dicti dict_get(dict *m, dicti k);
SDB_API dicti dict_get(dict *m, dicti k);
SDB_API void *dict_getu(dict *m, dicti k);
SDB_API bool dict_add(dict *m, dicti k, dicti v, void *u);
SDB_API bool dict_del(dict *m, dicti k);
SDB_API void dict_foreach(dict *m, dictkv_cb cb, void *u);

View File

@ -1,108 +0,0 @@
/* radare2 - BSD 3 Clause License - 2016 - crowell */
#ifndef HT_TYPE
#error HT_TYPE should be defined before including this header
#endif
#undef HtName_
#undef Ht_
#undef HT_
#undef KEY_TYPE
#undef VALUE_TYPE
#undef KEY_TO_HASH
#undef HT_NULL_VALUE
#if HT_TYPE == 1
#define HtName_(name) name##PP
#define Ht_(name) ht_pp_##name
#define HT_(name) HtPP##name
#define KEY_TYPE void *
#define VALUE_TYPE void *
#define KEY_TO_HASH(x) ((ut32)(uintptr_t)(x))
#define HT_NULL_VALUE NULL
#elif HT_TYPE == 2
#define HtName_(name) name##UP
#define Ht_(name) ht_up_##name
#define HT_(name) HtUP##name
#define KEY_TYPE ut64
#define VALUE_TYPE void *
#define KEY_TO_HASH(x) ((ut32)(x))
#define HT_NULL_VALUE 0
#else
#define HtName_(name) name##UU
#define Ht_(name) ht_uu_##name
#define HT_(name) HtUU##name
#define KEY_TYPE ut64
#define VALUE_TYPE ut64
#define KEY_TO_HASH(x) ((ut32)(x))
#define HT_NULL_VALUE 0
#endif
#include "ls.h"
#include "types.h"
/* Kv represents a single key/value element in the hashtable */
typedef struct Ht_(kv) {
KEY_TYPE key;
VALUE_TYPE value;
ut32 key_len;
ut32 value_len;
} HT_(Kv);
typedef void (*HT_(KvFreeFunc))(HT_(Kv) *);
typedef KEY_TYPE (*HT_(DupKey))(const KEY_TYPE);
typedef VALUE_TYPE (*HT_(DupValue))(const VALUE_TYPE);
typedef ut32 (*HT_(CalcSizeK))(const KEY_TYPE);
typedef ut32 (*HT_(CalcSizeV))(const VALUE_TYPE);
typedef ut32 (*HT_(HashFunction))(const KEY_TYPE);
typedef int (*HT_(ListComparator))(const KEY_TYPE, const KEY_TYPE);
typedef bool (*HT_(ForeachCallback))(void *user, const KEY_TYPE, const VALUE_TYPE);
typedef struct Ht_(bucket_t) {
HT_(Kv) *arr;
ut32 count;
} HT_(Bucket);
/* Options contain all the settings of the hashtable */
typedef struct Ht_(options_t) {
HT_(ListComparator) cmp; // Function for comparing values. Returns 0 if eq.
HT_(HashFunction) hashfn; // Function for hashing items in the hash table.
HT_(DupKey) dupkey; // Function for making a copy of key
HT_(DupValue) dupvalue; // Function for making a copy of value
HT_(CalcSizeK) calcsizeK; // Function to determine the key's size
HT_(CalcSizeV) calcsizeV; // Function to determine the value's size
HT_(KvFreeFunc) freefn; // Function to free the keyvalue store
size_t elem_size; // Size of each HtKv element (useful for subclassing like SdbKv)
} HT_(Options);
/* Ht is the hashtable structure */
typedef struct Ht_(t) {
ut32 size; // size of the hash table in buckets.
ut32 count; // number of stored elements.
HT_(Bucket)* table; // Actual table.
ut32 prime_idx;
HT_(Options) opt;
} HtName_(Ht);
// Create a new Ht with the provided Options
SDB_API HtName_(Ht)* Ht_(new_opt)(HT_(Options) *opt);
// Destroy a hashtable and all of its entries.
SDB_API void Ht_(free)(HtName_(Ht)* ht);
// Insert a new Key-Value pair into the hashtable. If the key already exists, returns false.
SDB_API bool Ht_(insert)(HtName_(Ht)* ht, const KEY_TYPE key, VALUE_TYPE value);
// Insert a new Key-Value pair into the hashtable, or updates the value if the key already exists.
SDB_API bool Ht_(update)(HtName_(Ht)* ht, const KEY_TYPE key, VALUE_TYPE value);
// Update the key of an element in the hashtable
SDB_API bool Ht_(update_key)(HtName_(Ht)* ht, const KEY_TYPE old_key, const KEY_TYPE new_key);
// Delete a key from the hashtable.
SDB_API bool Ht_(delete)(HtName_(Ht)* ht, const KEY_TYPE key);
// Find the value corresponding to the matching key.
SDB_API VALUE_TYPE Ht_(find)(HtName_(Ht)* ht, const KEY_TYPE key, bool* found);
// Iterates over all elements in the hashtable, calling the cb function on each Kv.
// If the cb returns false, the iteration is stopped.
// cb should not modify the hashtable.
// NOTE: cb can delete the current element, but it should be avoided
SDB_API void Ht_(foreach)(HtName_(Ht) *ht, HT_(ForeachCallback) cb, void *user);
SDB_API HT_(Kv)* Ht_(find_kv)(HtName_(Ht)* ht, const KEY_TYPE key, bool* found);
SDB_API bool Ht_(insert_kv)(HtName_(Ht) *ht, HT_(Kv) *kv, bool update);

View File

@ -1,16 +0,0 @@
#ifndef SDB_HT_PP_H
#define SDB_HT_PP_H
/*
* This header provides an hashtable HtPP that has void* as key and void* as
* value. The API functions starts with "ht_pp_" and the types starts with "HtPP".
*/
#define HT_TYPE 1
#include "ht_inc.h"
SDB_API HtName_(Ht)* Ht_(new0)(void);
SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize);
SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize);
#undef HT_TYPE
#endif

View File

@ -1,16 +0,0 @@
#ifndef SDB_HT_UP_H
#define SDB_HT_UP_H
/*
* This header provides an hashtable HtUP that has ut64 as key and void* as
* value. The API functions starts with "ht_up_" and the types starts with "HtUP".
*/
#define HT_TYPE 2
#include "ht_inc.h"
SDB_API HtName_(Ht)* Ht_(new0)(void);
SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize);
SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize);
#undef HT_TYPE
#endif

View File

@ -1,14 +0,0 @@
#ifndef SDB_HT_H_
#define SDB_HT_H_
/*
* This header provides an hashtable Ht that has ut64 as key and ut64 as
* value. The API functions starts with "ht_" and the types starts with "Ht".
*/
#define HT_TYPE 0
#include "ht_inc.h"
SDB_API HtName_(Ht)* Ht_(new0)(void);
#undef HT_TYPE
#endif

View File

@ -1,75 +0,0 @@
#ifndef LS_H
#define LS_H
#include <stdio.h>
#include "types.h"
typedef void (*SdbListFree)(void *ptr);
typedef int (*SdbListComparator)(const void *a, const void *b);
typedef struct ls_iter_t {
void *data;
struct ls_iter_t *n, *p;
} SdbListIter;
typedef struct ls_t {
size_t length;
SdbListIter *head;
SdbListIter *tail;
SdbListFree free;
SdbListComparator cmp;
bool sorted;
} SdbList;
#define ls_foreach(list, it, pos) \
if ((list)) \
for (it = (list)->head; it && (pos = it->data); it = it->n)
#define ls_foreach_safe(list, it, tmp, pos) \
if ((list)) \
for (it = list->head; \
it && (pos = it->data) && ((tmp = it->n) || 1); it = tmp)
#define ls_foreach_prev(list, it, pos) \
if ((list)) \
for (it = list->tail; it && (pos = it->data); it = it->p)
#define ls_iterator(x) (x)?(x)->head:NULL
// #define ls_empty(x) (!x || (!x->head && !x->tail))
#define ls_empty(x) (!x || !x->length)
#define ls_head(x) x->head
#define ls_tail(x) x->tail
#define ls_unref(x) x
#define ls_iter_get(x) x->data; x=x->n
#define ls_iter_next(x) (x?1:0)
#define ls_iter_cur(x) x->p
#define ls_iter_unref(x) x
#define ls_length(x) x->length
SDB_API SdbList *ls_new(void);
SDB_API SdbList *ls_newf(SdbListFree freefn);
SDB_API SdbListIter *ls_append(SdbList *list, void *data);
SDB_API SdbListIter *ls_prepend(SdbList *list, void *data);
//SDB_API void ls_add_sorted(SdbList *list, void *data, SdbListComparator cmp);
SDB_API bool ls_sort(SdbList *list, SdbListComparator cmp);
SDB_API bool ls_merge_sort(SdbList *list, SdbListComparator cmp);
SDB_API void ls_delete(SdbList *list, SdbListIter *iter);
SDB_API bool ls_delete_data(SdbList *list, void *ptr);
SDB_API void ls_iter_init(SdbListIter *iter, SdbList *list);
SDB_API void ls_destroy(SdbList *list);
SDB_API void ls_free(SdbList *list);
SDB_API SdbListIter *ls_item_new(void *data);
SDB_API void ls_unlink(SdbList *list, void *ptr);
SDB_API void ls_split(SdbList *list, void *ptr);
// Removes element `iter` from `list`.
SDB_API void ls_split_iter(SdbList *list, SdbListIter *iter);
SDB_API void *ls_get_n(SdbList *list, int n);
SDB_API void *ls_get_top(SdbList *list);
#define ls_push(x,y) ls_append(x,y)
SDB_API void *ls_pop(SdbList *list);
SDB_API void ls_reverse(SdbList *list);
SDB_API SdbList *ls_clone(SdbList *list);
SDB_API int ls_join(SdbList *first, SdbList *second);
SDB_API int ls_del_n(SdbList *list, int n);
SDB_API SdbListIter *ls_insert(SdbList *list, int n, void *data);
SDB_API void *ls_pop_head(SdbList *list);
#endif

View File

@ -1,390 +0,0 @@
#ifndef SDB_H
#define SDB_H
#if !defined(O_BINARY) && !defined(_MSC_VER)
#undef O_BINARY
#define O_BINARY 0
#endif
#ifdef __cplusplus
extern "C" {
#endif
#include "types.h"
#include "sdbht.h"
#include "ls.h"
#include "dict.h"
#include "cdb.h"
#include "cdb_make.h"
#include "sdb_version.h"
/* Key value sizes */
#define SDB_MIN_VALUE 1
#define SDB_MAX_VALUE 0xffffff
#define SDB_MIN_KEY 1
#define SDB_MAX_KEY 0xff
#if !defined(SZT_ADD_OVFCHK)
#define SZT_ADD_OVFCHK(x, y) ((SIZE_MAX - (x)) <= (y))
#endif
#if __SDB_WINDOWS__ && !__CYGWIN__
#include <windows.h>
#include <fcntl.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#ifndef _MSC_VER
extern __attribute__((dllimport)) void *__cdecl _aligned_malloc(size_t, size_t);
extern __attribute__((dllimport)) void __cdecl _aligned_free(void *memblock);
extern char *strdup (const char *);
#else
#include <process.h>
#include <windows.h>
#include <malloc.h> // for _aligned_malloc
#define ftruncate _chsize
#endif
//#define SDB_MODE 0
#define SDB_MODE _S_IWRITE | _S_IREAD
#else
#define SDB_MODE 0644
//#define SDB_MODE 0600
#endif
//#define SDB_RS '\x1e'
#define SDB_RS ','
#define SDB_SS ","
#define SDB_MAX_PATH 256
#define SDB_NUM_BASE 16
#define SDB_NUM_BUFSZ 64
#define SDB_OPTION_NONE 0
#define SDB_OPTION_ALL 0xff
#define SDB_OPTION_SYNC (1 << 0)
#define SDB_OPTION_NOSTAMP (1 << 1)
#define SDB_OPTION_FS (1 << 2)
#define SDB_OPTION_JOURNAL (1 << 3)
#define SDB_LIST_UNSORTED 0
#define SDB_LIST_SORTED 1
// This size implies trailing zero terminator, this is 254 chars + 0
#define SDB_KSZ 0xff
#define SDB_VSZ 0xffffff
typedef struct sdb_t {
char *dir; // path+name
char *path;
char *name;
int fd;
int refs; // reference counter
int lock;
int journal;
struct cdb db;
struct cdb_make m;
HtPP *ht;
ut32 eod;
ut32 pos;
int fdump;
char *ndump;
ut64 expire;
ut64 last; // timestamp of last change
int options;
int ns_lock; // TODO: merge into options?
SdbList *ns;
SdbList *hooks;
SdbKv tmpkv;
ut32 depth;
bool timestamped;
SdbMini mht;
} Sdb;
typedef struct sdb_ns_t {
char *name;
ut32 hash;
Sdb *sdb;
} SdbNs;
SDB_API Sdb* sdb_new0(void);
SDB_API Sdb* sdb_new(const char *path, const char *file, int lock);
SDB_API int sdb_open(Sdb *s, const char *file);
SDB_API void sdb_close(Sdb *s);
SDB_API void sdb_config(Sdb *s, int options);
SDB_API bool sdb_free(Sdb* s);
SDB_API void sdb_file(Sdb* s, const char *dir);
SDB_API bool sdb_merge(Sdb* d, Sdb *s);
SDB_API int sdb_count(Sdb* s);
SDB_API void sdb_reset(Sdb* s);
SDB_API void sdb_setup(Sdb* s, int options);
SDB_API void sdb_drain(Sdb*, Sdb*);
// Copy everything, including namespaces, from src to dst
SDB_API void sdb_copy(Sdb *src, Sdb *dst);
SDB_API bool sdb_stats(Sdb *s, ut32 *disk, ut32 *mem);
SDB_API bool sdb_dump_hasnext (Sdb* s);
typedef bool (*SdbForeachCallback)(void *user, const char *k, const char *v);
SDB_API bool sdb_foreach(Sdb* s, SdbForeachCallback cb, void *user);
SDB_API SdbList *sdb_foreach_list(Sdb* s, bool sorted);
SDB_API SdbList *sdb_foreach_list_filter(Sdb* s, SdbForeachCallback filter, bool sorted);
SDB_API SdbList *sdb_foreach_match(Sdb* s, const char *expr, bool sorted);
SDB_API int sdb_query(Sdb* s, const char *cmd);
SDB_API int sdb_queryf(Sdb* s, const char *fmt, ...);
SDB_API int sdb_query_lines(Sdb *s, const char *cmd);
SDB_API char *sdb_querys(Sdb* s, char *buf, size_t len, const char *cmd);
SDB_API char *sdb_querysf(Sdb* s, char *buf, size_t buflen, const char *fmt, ...);
SDB_API int sdb_query_file(Sdb *s, const char* file);
SDB_API bool sdb_exists(Sdb*, const char *key);
SDB_API bool sdb_remove(Sdb*, const char *key, ut32 cas);
SDB_API int sdb_unset(Sdb*, const char *key, ut32 cas);
SDB_API int sdb_unset_like(Sdb *s, const char *k);
SDB_API char** sdb_like(Sdb *s, const char *k, const char *v, SdbForeachCallback cb);
// diffing
typedef struct sdb_diff_t {
const SdbList *path;
const char *k;
const char *v; // if null, k is a namespace
bool add;
} SdbDiff;
// Format diff in a readable form into str. str, size and return are like in snprintf.
SDB_API int sdb_diff_format(char *str, int size, const SdbDiff *diff);
typedef void (*SdbDiffCallback)(const SdbDiff *diff, void *user);
// Returns true iff the contents of a and b are equal including contained namespaces
// If cb is non-null, it will be called subsequently with differences.
SDB_API bool sdb_diff(Sdb *a, Sdb *b, SdbDiffCallback cb, void *cb_user);
// Gets a pointer to the value associated with `key`.
SDB_API char *sdb_get(Sdb*, const char *key, ut32 *cas);
// Gets a pointer to the value associated with `key` and returns in `vlen` the
// length of the value string.
SDB_API char *sdb_get_len(Sdb*, const char *key, int *vlen, ut32 *cas);
// Gets a const pointer to the value associated with `key`
SDB_API const char *sdb_const_get(Sdb*, const char *key, ut32 *cas);
// Gets a const pointer to the value associated with `key` and returns in
// `vlen` the length of the value string.
SDB_API const char *sdb_const_get_len(Sdb* s, const char *key, int *vlen, ut32 *cas);
SDB_API int sdb_set(Sdb*, const char *key, const char *data, ut32 cas);
SDB_API int sdb_set_owned(Sdb* s, const char *key, char *val, ut32 cas);
SDB_API int sdb_concat(Sdb *s, const char *key, const char *value, ut32 cas);
SDB_API int sdb_uncat(Sdb *s, const char *key, const char *value, ut32 cas);
SDB_API int sdb_add(Sdb* s, const char *key, const char *val, ut32 cas);
SDB_API bool sdb_sync(Sdb*);
SDB_API void sdbkv_free(SdbKv *kv);
/* num.c */
SDB_API bool sdb_num_exists(Sdb*, const char *key);
SDB_API int sdb_num_base(const char *s);
SDB_API ut64 sdb_num_get(Sdb* s, const char *key, ut32 *cas);
SDB_API int sdb_num_set(Sdb* s, const char *key, ut64 v, ut32 cas);
SDB_API int sdb_num_add(Sdb *s, const char *key, ut64 v, ut32 cas);
SDB_API ut64 sdb_num_inc(Sdb* s, const char *key, ut64 n, ut32 cas);
SDB_API ut64 sdb_num_dec(Sdb* s, const char *key, ut64 n, ut32 cas);
SDB_API int sdb_num_min(Sdb* s, const char *key, ut64 v, ut32 cas);
SDB_API int sdb_num_max(Sdb* s, const char *key, ut64 v, ut32 cas);
/* ptr */
SDB_API int sdb_ptr_set(Sdb *db, const char *key, void *p, ut32 cas);
SDB_API void* sdb_ptr_get(Sdb *db, const char *key, ut32 *cas);
/* create db */
SDB_API bool sdb_disk_create(Sdb* s);
SDB_API bool sdb_disk_insert(Sdb* s, const char *key, const char *val);
SDB_API bool sdb_disk_finish(Sdb* s);
SDB_API bool sdb_disk_unlink(Sdb* s);
/* iterate */
SDB_API void sdb_dump_begin(Sdb* s);
SDB_API SdbKv *sdb_dump_next(Sdb* s);
SDB_API bool sdb_dump_dupnext(Sdb* s, char *key, char **value, int *_vlen);
/* journaling */
SDB_API bool sdb_journal_close(Sdb *s);
SDB_API bool sdb_journal_open(Sdb *s);
SDB_API int sdb_journal_load(Sdb *s);
SDB_API bool sdb_journal_log(Sdb *s, const char *key, const char *val);
SDB_API bool sdb_journal_clear(Sdb *s);
SDB_API bool sdb_journal_unlink(Sdb *s);
/* numeric */
SDB_API char *sdb_itoa(ut64 n, char *s, int base);
SDB_API ut64 sdb_atoi(const char *s);
SDB_API const char *sdb_itoca(ut64 n);
/* locking */
SDB_API bool sdb_lock(const char *s);
SDB_API const char *sdb_lock_file(const char *f);
SDB_API void sdb_unlock(const char *s);
SDB_API bool sdb_unlink(Sdb* s);
SDB_API int sdb_lock_wait(const char *s UNUSED);
/* expiration */
SDB_API bool sdb_expire_set(Sdb* s, const char *key, ut64 expire, ut32 cas);
SDB_API ut64 sdb_expire_get(Sdb* s, const char *key, ut32 *cas);
SDB_API ut64 sdb_now(void);
SDB_API ut64 sdb_unow(void);
SDB_API ut32 sdb_hash(const char *key);
SDB_API ut32 sdb_hash_len(const char *key, ut32 *len);
SDB_API ut8 sdb_hash_byte(const char *s);
/* json api */
// SDB_API int sdb_js0n(const unsigned char *js, RangstrType len, RangstrType *out);
SDB_API bool sdb_isjson(const char *k);
SDB_API char *sdb_json_get_str (const char *json, const char *path);
SDB_API bool sdb_json_get_bool(const char *json, const char *path);
SDB_API char *sdb_json_get(Sdb* s, const char *key, const char *p, ut32 *cas);
SDB_API bool sdb_json_set(Sdb* s, const char *k, const char *p, const char *v, ut32 cas);
SDB_API int sdb_json_num_get(Sdb* s, const char *k, const char *p, ut32 *cas);
SDB_API int sdb_json_num_set(Sdb* s, const char *k, const char *p, int v, ut32 cas);
SDB_API int sdb_json_num_dec(Sdb* s, const char *k, const char *p, int n, ut32 cas);
SDB_API int sdb_json_num_inc(Sdb* s, const char *k, const char *p, int n, ut32 cas);
SDB_API char *sdb_json_indent(const char *s, const char *tab);
SDB_API char *sdb_json_unindent(const char *s);
typedef struct {
char *buf;
size_t blen;
size_t len;
} SdbJsonString;
SDB_API const char *sdb_json_format(SdbJsonString* s, const char *fmt, ...);
#define sdb_json_format_free(x) free ((x)->buf)
// namespace
SDB_API Sdb* sdb_ns(Sdb *s, const char *name, int create);
SDB_API Sdb *sdb_ns_path(Sdb *s, const char *path, int create);
SDB_API void sdb_ns_init(Sdb* s);
SDB_API void sdb_ns_free(Sdb* s);
SDB_API void sdb_ns_lock(Sdb *s, int lock, int depth);
SDB_API void sdb_ns_sync(Sdb* s);
SDB_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r);
SDB_API bool sdb_ns_unset(Sdb *s, const char *name, Sdb *r);
// array
SDB_API bool sdb_array_contains(Sdb* s, const char *key, const char *val, ut32 *cas);
SDB_API bool sdb_array_contains_num(Sdb *s, const char *key, ut64 val, ut32 *cas);
SDB_API int sdb_array_indexof(Sdb *s, const char *key, const char *val, ut32 cas);
SDB_API int sdb_array_set(Sdb* s, const char *key, int idx, const char *val, ut32 cas);
SDB_API int sdb_array_set_num(Sdb* s, const char *key, int idx, ut64 val, ut32 cas);
SDB_API bool sdb_array_append(Sdb *s, const char *key, const char *val, ut32 cas);
SDB_API bool sdb_array_append_num(Sdb *s, const char *key, ut64 val, ut32 cas);
SDB_API bool sdb_array_prepend(Sdb *s, const char *key, const char *val, ut32 cas);
SDB_API bool sdb_array_prepend_num(Sdb *s, const char *key, ut64 val, ut32 cas);
SDB_API char *sdb_array_get(Sdb* s, const char *key, int idx, ut32 *cas);
SDB_API ut64 sdb_array_get_num(Sdb* s, const char *key, int idx, ut32 *cas);
SDB_API int sdb_array_get_idx(Sdb *s, const char *key, const char *val, ut32 cas); // agetv
SDB_API int sdb_array_insert(Sdb* s, const char *key, int idx, const char *val, ut32 cas);
SDB_API int sdb_array_insert_num(Sdb* s, const char *key, int idx, ut64 val, ut32 cas);
SDB_API int sdb_array_unset(Sdb* s, const char *key, int n, ut32 cas); // leaves empty bucket
SDB_API int sdb_array_delete(Sdb* s, const char *key, int n, ut32 cas);
SDB_API void sdb_array_sort(Sdb* s, const char *key, ut32 cas);
SDB_API void sdb_array_sort_num(Sdb* s, const char *key, ut32 cas);
// set
// Adds string `val` at the end of array `key`.
SDB_API int sdb_array_add(Sdb* s, const char *key, const char *val, ut32 cas);
// Adds number `val` at the end of array `key`.
SDB_API int sdb_array_add_num(Sdb* s, const char *key, ut64 val, ut32 cas);
// Adds string `val` in the sorted array `key`.
SDB_API int sdb_array_add_sorted(Sdb *s, const char *key, const char *val, ut32 cas);
// Adds number `val` in the sorted array `key`.
SDB_API int sdb_array_add_sorted_num(Sdb *s, const char *key, ut64 val, ut32 cas);
// Removes the string `val` from the array `key`.
SDB_API int sdb_array_remove(Sdb *s, const char *key, const char *val, ut32 cas);
// Removes the number `val` from the array `key`.
SDB_API int sdb_array_remove_num(Sdb* s, const char *key, ut64 val, ut32 cas);
// helpers
SDB_API char *sdb_anext(char *str, char **next);
SDB_API const char *sdb_const_anext(const char *str);
SDB_API int sdb_alen(const char *str);
SDB_API int sdb_alen_ignore_empty(const char *str);
SDB_API int sdb_array_size(Sdb* s, const char *key);
SDB_API int sdb_array_length(Sdb* s, const char *key);
int sdb_array_list(Sdb* s, const char *key);
// Adds the string `val` to the start of array `key`.
SDB_API bool sdb_array_push(Sdb *s, const char *key, const char *val, ut32 cas);
// Returns the string at the start of array `key` or
// NULL if there are no elements.
SDB_API char *sdb_array_pop(Sdb *s, const char *key, ut32 *cas);
// Adds the number `val` to the start of array `key`.
SDB_API int sdb_array_push_num(Sdb *s, const char *key, ut64 num, ut32 cas);
// Returns the number at the start of array `key`.
SDB_API ut64 sdb_array_pop_num(Sdb *s, const char *key, ut32 *cas);
SDB_API char *sdb_array_pop_head(Sdb *s, const char *key, ut32 *cas);
SDB_API char *sdb_array_pop_tail(Sdb *s, const char *key, ut32 *cas);
typedef void (*SdbHook)(Sdb *s, void *user, const char *k, const char *v);
SDB_API void sdb_global_hook(SdbHook hook, void *user);
SDB_API bool sdb_hook(Sdb* s, SdbHook cb, void* user);
SDB_API bool sdb_unhook(Sdb* s, SdbHook h);
SDB_API int sdb_hook_call(Sdb *s, const char *k, const char *v);
SDB_API void sdb_hook_free(Sdb *s);
/* Util.c */
SDB_API int sdb_isnum(const char *s);
SDB_API bool sdb_isempty(Sdb *s);
SDB_API const char *sdb_type(const char *k);
SDB_API bool sdb_match(const char *str, const char *glob);
SDB_API int sdb_bool_set(Sdb *db, const char *str, bool v, ut32 cas);
SDB_API bool sdb_bool_get(Sdb *db, const char *str, ut32 *cas);
// base64
SDB_API ut8 *sdb_decode(const char *in, int *len);
SDB_API char *sdb_encode(const ut8 *bin, int len);
SDB_API void sdb_encode_raw(char *bout, const ut8 *bin, int len);
SDB_API int sdb_decode_raw(ut8 *bout, const char *bin, int len);
// binfmt
SDB_API char *sdb_fmt(const char *fmt, ...);
SDB_API int sdb_fmt_init(void *p, const char *fmt);
SDB_API void sdb_fmt_free(void *p, const char *fmt);
SDB_API int sdb_fmt_tobin(const char *_str, const char *fmt, void *stru);
SDB_API char *sdb_fmt_tostr(void *stru, const char *fmt);
SDB_API char** sdb_fmt_array(const char *list);
SDB_API ut64* sdb_fmt_array_num(const char *list);
// raw array helpers
SDB_API char *sdb_array_compact(char *p);
SDB_API char *sdb_aslice(char *out, int from, int to);
#define sdb_aforeach(x,y) \
{ char *next; \
if (y) for (x=y;;) { \
x = sdb_anext (x, &next);
#define sdb_aforeach_next(x) \
if (!next) break; \
*(next-1) = ','; \
x = next; } }
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1 +0,0 @@
#define SDB_VERSION "1.4.1"

View File

@ -1,52 +0,0 @@
#ifndef __SDB_HT_H
#define __SDB_HT_H
#include "ht_pp.h"
/** keyvalue pair **/
typedef struct sdb_kv {
//sub of HtPPKv so we can cast safely
HtPPKv base;
ut32 cas;
ut64 expire;
} SdbKv;
static inline char *sdbkv_key(const SdbKv *kv) {
return (char *)kv->base.key;
}
static inline char *sdbkv_value(const SdbKv *kv) {
return (char *)kv->base.value;
}
static inline ut32 sdbkv_key_len(const SdbKv *kv) {
return kv->base.key_len;
}
static inline ut32 sdbkv_value_len(const SdbKv *kv) {
return kv->base.value_len;
}
SDB_API SdbKv* sdbkv_new2(const char *k, int kl, const char *v, int vl);
SDB_API SdbKv* sdbkv_new(const char *k, const char *v);
extern SDB_API void sdbkv_free(SdbKv *kv);
extern SDB_API ut32 sdb_hash(const char *key);
SDB_API HtPP* sdb_ht_new(void);
// Destroy a hashtable and all of its entries.
SDB_API void sdb_ht_free(HtPP* ht);
// Insert a new Key-Value pair into the hashtable. If the key already exists, returns false.
SDB_API bool sdb_ht_insert(HtPP* ht, const char* key, const char* value);
// Insert a new Key-Value pair into the hashtable, or updates the value if the key already exists.
SDB_API bool sdb_ht_insert_kvp(HtPP* ht, SdbKv *kvp, bool update);
// Insert a new Key-Value pair into the hashtable, or updates the value if the key already exists.
SDB_API bool sdb_ht_update(HtPP* ht, const char* key, const char* value);
// Delete a key from the hashtable.
SDB_API bool sdb_ht_delete(HtPP* ht, const char* key);
// Find the value corresponding to the matching key.
SDB_API char* sdb_ht_find(HtPP* ht, const char* key, bool* found);
// Find the KeyValuePair corresponding to the matching key.
SDB_API SdbKv* sdb_ht_find_kvp(HtPP* ht, const char* key, bool* found);
#endif // __SDB_HT_H

View File

@ -1,23 +0,0 @@
#ifndef SDB_SET_H
#define SDB_SET_H
#include "ht_pp.h"
#include "ht_up.h"
typedef HtPP SetP;
SDB_API SetP *set_p_new(void);
SDB_API void set_p_add(SetP *p, void *u);
SDB_API bool set_p_contains(SetP *s, void *u);
SDB_API void set_p_delete(SetP *s, void *u);
SDB_API void set_p_free(SetP *p);
typedef HtUP SetU;
SDB_API SetU *set_u_new(void);
SDB_API void set_u_add(SetU *p, ut64 u);
SDB_API bool set_u_contains(SetU *s, ut64 u);
SDB_API void set_u_delete(SetU *s, ut64 u);
SDB_API void set_u_free(SetU *p);
#endif

View File

@ -1,135 +0,0 @@
#ifndef TYPES_H
#define TYPES_H
#include <sys/types.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#undef eprintf
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#ifndef SDB_API
#if defined(__GNUC__) && __GNUC__ >= 4
#define SDB_API __attribute__((visibility("default")))
#else
#define SDB_API
#endif
#endif
#ifndef SDB_IPI
#if defined(__GNUC__) && __GNUC__ >= 4
// __attribute__((visibility("hidden")))
#endif
#define SDB_IPI static
#endif
#if MINGW || __MINGW32__ || __MINGW64__
#define __MINGW__ 1
#endif
#if __WIN32__ || __MINGW__ || __WINDOWS__ || _MSC_VER
#define __SDB_WINDOWS__ 1
#define DIRSEP '\\'
#include <windows.h>
#include <io.h>
#else
// CYGWIN AND UNIX
#define __SDB_WINDOWS__ 0
#define DIRSEP '/'
#include <unistd.h>
#endif
#include <inttypes.h>
#if __SDB_WINDOWS__ && !__CYGWIN__
#define HAVE_MMAN 0
#define ULLFMT "I64"
#else
#define HAVE_MMAN 1
#define ULLFMT "ll"
#endif
#ifndef USE_MMAN
#define USE_MMAN HAVE_MMAN
#endif
#ifndef UNUSED
# define UNUSED
# ifdef __GNUC__
# if __GNUC__ >= 4
# undef UNUSED
# define UNUSED __attribute__((__unused__))
# endif
# endif
#endif
#ifndef ut8
#define ut8 unsigned char
#define ut32 unsigned int
#define ut64 unsigned long long
#define st64 long long
#define boolt int
// TODO: deprecate R_NEW
#ifndef R_NEW
//it means we are within sdb
#define R_NEW(x) (x*)malloc(sizeof(x))
#endif
#ifndef R_NEW0
#define R_NEW0(x) (x*)calloc(1, sizeof(x))
#endif
#ifndef R_FREE
#define R_FREE(x) { free (x); x = NULL; }
#endif
#define UT32_MAX ((ut32)0xffffffff)
#define UT64_MAX ((ut64)(0xffffffffffffffffLL))
#endif
#ifndef R_MAX_DEFINED
#define R_MAX(x,y) (((x)>(y))?(x):(y))
#define R_MAX_DEFINED 1
#endif
#ifndef R_MIN_DEFINED
#define R_MIN(x,y) (((x)>(y))?(y):(x))
#define R_MIN_DEFINED 1
#endif
#include "config.h"
static inline int seek_set(int fd, off_t pos) {
return ((fd == -1) || (lseek (fd, (off_t) pos, SEEK_SET) == -1))? 0:1;
}
static inline void ut32_pack(char s[4], ut32 u) {
s[0] = u & 255;
u >>= 8;
s[1] = u & 255;
u >>= 8;
s[2] = u & 255;
s[3] = u >> 8;
}
static inline void ut32_pack_big(char s[4], ut32 u) {
s[3] = u & 255;
u >>= 8;
s[2] = u & 255;
u >>= 8;
s[1] = u & 255;
s[0] = u >> 8;
}
static inline void ut32_unpack(char s[4], ut32 *u) {
ut32 result = 0;
result = (ut8) s[3];
result <<= 8;
result += (ut8) s[2];
result <<= 8;
result += (ut8) s[1];
result <<= 8;
result += (ut8) s[0];
*u = result;
}
#endif

View File

@ -16,7 +16,7 @@ spp_inc = [platform_inc, include_directories('../../shlr/spp')]
r_lang = library('r_lang', r_lang_sources,
include_directories: [platform_inc, spp_inc],
c_args: library_cflags,
dependencies: [r_util_dep, spp_dep, r_cons_dep],
dependencies: [r_util_dep, r_cons_dep],
install: true,
implicit_include_directories: false,
soversion: r2_libversion

View File

@ -379,7 +379,6 @@ include_files =[
'include/r_types.h',
'include/r_util.h',
'include/r_vector.h',
'include/sdb.h'
]
install_headers(include_files, install_dir: r2_incdir)
@ -445,25 +444,6 @@ r_crypto_files = [
]
install_headers(r_crypto_files, install_dir: join_paths(r2_incdir, 'r_crypto'))
sdb_files = [
'include/sdb/buffer.h',
'include/sdb/cdb.h',
'include/sdb/set.h',
'include/sdb/cdb_make.h',
'include/sdb/config.h',
'include/sdb/dict.h',
'include/sdb/ht_inc.h',
'include/sdb/ht_pp.h',
'include/sdb/ht_up.h',
'include/sdb/ht_uu.h',
'include/sdb/ls.h',
'include/sdb/sdb.h',
'include/sdb/sdbht.h',
'include/sdb/sdb_version.h',
'include/sdb/types.h'
]
install_headers(sdb_files, install_dir: join_paths(r2_incdir, 'sdb'))
sflib_common_files = [
'include/sflib/common/sftypes.h',
'include/sflib/common/sfsocketcall.h'

View File

@ -19,6 +19,8 @@ ALL?=
CFLAGS+=-I$(LIBR)
CFLAGS+=-I$(LIBR)/include
-include $(SHLR)/sdb.mk
CFLAGS+=-fvisibility=hidden
LDFLAGS+=-fvisibility=hidden
LINK+=-fvisibility=hidden

View File

@ -26,7 +26,8 @@ r_socket = library('r_socket', r_socket_sources,
)
r_socket_dep = declare_dependency(link_with: r_socket,
include_directories: [platform_inc])
dependencies: [r_util_dep],
include_directories: [platform_inc])
pkgconfig_mod.generate(r_socket,
subdirs: 'libr',

View File

@ -110,7 +110,7 @@ r_util_dep = declare_dependency(link_with: r_util,
dependencies: r_util_deps)
pkgconfig_mod.generate(r_util,
subdirs: 'libr',
subdirs: ['libr', 'libr/sdb'],
version: r2_version,
libraries: pkgcfg_sanitize_libs,
name: 'r_util',

View File

@ -32,7 +32,7 @@ SDBOBJS=$(addprefix ${SDBPATH},${SDB_OBJS})
OBJS+=$(SDBOBJS)
CFLAGS+=-I$(SDBPATH)/src
CFLAGS+=-I$(SDBPATH)
sdb_version:
$(MAKE) -C "$(SDBPATH)" sdb_version.h

View File

@ -398,6 +398,166 @@ libr_pc = configure_file(
install_dir: join_paths(get_option('libdir'), 'pkgconfig')
)
# handle zlib dependency
zlib_dep = dependency('zlib', required: false)
if not zlib_dep.found() or not get_option('use_sys_zlib')
message('Use bundled zlib')
zlib_files = [
'shlr/zip/zlib/adler32.c',
'shlr/zip/zlib/compress.c',
'shlr/zip/zlib/crc32.c',
'shlr/zip/zlib/deflate.c',
'shlr/zip/zlib/gzclose.c',
'shlr/zip/zlib/gzlib.c',
'shlr/zip/zlib/gzread.c',
'shlr/zip/zlib/gzwrite.c',
'shlr/zip/zlib/infback.c',
'shlr/zip/zlib/inffast.c',
'shlr/zip/zlib/inflate.c',
'shlr/zip/zlib/inftrees.c',
'shlr/zip/zlib/trees.c',
'shlr/zip/zlib/uncompr.c',
'shlr/zip/zlib/zutil.c'
]
zlib_inc = [platform_inc, include_directories('shlr/zip/zlib')]
libr2zlib = static_library('r2zlib', zlib_files,
include_directories: zlib_inc,
implicit_include_directories: false
)
zlib_dep = declare_dependency(
link_with: libr2zlib,
include_directories: zlib_inc
)
else
message('Use system-provided zlib library')
endif
# handle sdb dependency
# NOTE: copying most of the stuff from sdb to here for the moment, since we
# should use subpackages to handle this well
sdb_files = [
'shlr/sdb/src/array.c',
'shlr/sdb/src/base64.c',
'shlr/sdb/src/buffer.c',
'shlr/sdb/src/set.c',
'shlr/sdb/src/cdb.c',
'shlr/sdb/src/cdb_make.c',
'shlr/sdb/src/dict.c',
'shlr/sdb/src/diff.c',
'shlr/sdb/src/disk.c',
'shlr/sdb/src/fmt.c',
'shlr/sdb/src/ht_uu.c',
'shlr/sdb/src/ht_up.c',
'shlr/sdb/src/ht_pp.c',
'shlr/sdb/src/journal.c',
'shlr/sdb/src/json.c',
'shlr/sdb/src/lock.c',
'shlr/sdb/src/ls.c',
'shlr/sdb/src/match.c',
'shlr/sdb/src/ns.c',
'shlr/sdb/src/num.c',
'shlr/sdb/src/query.c',
'shlr/sdb/src/sdb.c',
'shlr/sdb/src/sdbht.c',
'shlr/sdb/src/util.c'
]
sdb_inc = [platform_inc, include_directories('shlr/sdb/src')]
# Create sdb_version.h
r = run_command(py3_exe, 'sys/sdb_version.py', 'shlr/sdb/config.mk')
if r.returncode() == 0
sdb_version = r.stdout().strip().split('\n')[0]
else
sdb_version = 'unknown'
endif
run_command(py3_exe, '-c', 'with open("shlr/sdb/src/sdb_version.h", "w") as f: f.write("#define SDB_VERSION \"' + sdb_version + '\"")')
sdb_inc_files = [
'shlr/sdb/src/buffer.h',
'shlr/sdb/src/cdb.h',
'shlr/sdb/src/set.h',
'shlr/sdb/src/cdb_make.h',
'shlr/sdb/src/config.h',
'shlr/sdb/src/dict.h',
'shlr/sdb/src/ht_inc.h',
'shlr/sdb/src/ht_pp.h',
'shlr/sdb/src/ht_up.h',
'shlr/sdb/src/ht_uu.h',
'shlr/sdb/src/ls.h',
'shlr/sdb/src/sdb.h',
'shlr/sdb/src/sdbht.h',
'shlr/sdb/src/sdb_version.h',
'shlr/sdb/src/types.h'
]
install_headers(sdb_inc_files, install_dir: join_paths(r2_incdir, 'sdb'))
libr2sdb = static_library('r2sdb', sdb_files,
include_directories: sdb_inc,
implicit_include_directories: false,
c_args: host_machine.system() == 'windows' ? '-DSDB_API=__declspec(dllexport)' : [],
)
sdb_dep = declare_dependency(
link_whole: libr2sdb,
include_directories: sdb_inc
)
sdb_exe = executable('sdb', ['shlr/sdb/src/main.c'] + sdb_files,
include_directories: [
include_directories(['shlr/sdb/src'])
],
implicit_include_directories: false,
native: true,
)
sdb_gen_cmd_script = '''#script
import os
import sys
sdb_exe = r'@0@'
outfile = sys.argv[1]
infiles = sys.argv[2:]
if os.name == 'nt':
# DO NOT replace chr(92) below with a backslash
infiles, sdb_exe, outfile = map(lambda x: x.replace('/', chr(92)), [' '.join(infiles), sdb_exe, outfile])
os.system('type {} | {} {} ='.format(infiles, sdb_exe, outfile))
else:
infiles = ' '.join(infiles)
os.system('cat {} | {} {} ='.format(infiles, sdb_exe, outfile))
'''.format(sdb_exe.full_path())
sdb_gen_cmd = [
py3_exe,
'-c',
sdb_gen_cmd_script,
'@OUTPUT@',
'@INPUT@'
]
# handle spp dependency
spp_files = [
'shlr/spp/spp.c'
]
spp_inc = [platform_inc, include_directories('shlr/spp')]
libr2spp = static_library('r2spp', spp_files,
dependencies: sdb_dep,
include_directories: spp_inc,
c_args: ['-DHAVE_R_UTIL', '-DUSE_R2=1'],
implicit_include_directories: false
)
spp_dep = declare_dependency(
link_with: libr2spp,
include_directories: spp_inc
)
pkgcfg_sanitize_libs = ''
if get_option('b_sanitize').contains('address')
pkgcfg_sanitize_libs += ' -lasan'
@ -406,12 +566,12 @@ if get_option('b_sanitize').contains('undefined')
pkgcfg_sanitize_libs += ' -lubsan'
endif
subdir('libr/util')
subdir('libr/socket')
subdir('shlr')
subdir('libr/util')
subdir('libr/hash')
subdir('libr/crypto')
subdir('libr/socket')
subdir('libr/cons')
subdir('shlr/gdb')
subdir('libr/io')

View File

@ -8,4 +8,4 @@ Description: radare foundation libraries
Version: @VERSION@
Requires:
Libs: -L${libdir} -lr_util @LIBZIP@ @DL_LIBS@
Cflags: -I${includedir}/libr
Cflags: -I${includedir}/libr -I${includedir}/libr/sdb

View File

@ -129,7 +129,7 @@ endif
targets:
for TARGET in ${SDB_TARGETS} ; do ${MAKE} $$TARGET ; done
${SDB_TARGETS}:
sdb/src/sdb_version.h:
@echo
@echo BUILD SUMARY
@echo ============
@ -139,32 +139,36 @@ ${SDB_TARGETS}:
@echo HOST_OS ${HOST_OS}
@echo BUILD_OS ${BUILD_OS}
@echo ============
$(MAKE) -C sdb clean
$(MAKE) -C sdb src/sdb_version.h
sdb-native-build: sdb/src/sdb_version.h
@echo
@echo ">>>>>>>>>>>>>>>>"
@echo "NATIVE BUILD SDB"
@echo ">>>>>>>>>>>>>>>>"
@echo
$(MAKE) -C sdb clean
$(MAKE) -C sdb src/sdb_version.h
$(MAKE) -C sdb/src CC=${HOST_CC} LDFLAGS='${HOST_LDFLAGS}' CPPFLAGS='' CFLAGS='${HOST_CFLAGS} ${PIC}' bin
cp -f sdb/src/sdb${BUILD_EXT_EXE} sdb/src/.sdb${BUILD_EXT_EXE}
sdb-target-build: sdb/src/sdb_version.h
@echo
@echo ">>>>>>>>>>>>>>>>"
@echo "TARGET BUILD SDB"
@echo ">>>>>>>>>>>>>>>>"
@echo
$(MAKE) -C sdb clean
cd sdb ; $(MAKE) src/sdb_version.h
cd sdb/src ; $(MAKE) ARCH=xxx RANLIB="${RANLIB}" CFLAGS_SHARED="${CFLAGS_SHARED}" \
CC="${CC}" AR="${AR}" CFLAGS='${CFLAGS}' LDFLAGS='${LDFLAGS}' libsdb.a
${RANLIB} sdb/src/libsdb.a
${SDB_TARGETS}: sdb-native-build sdb-target-build
ifneq (${EXT_AR},a)
-cp -f sdb/src/libsdb.a sdb/src/libsdb.${EXT_AR}
endif
rm -f $@
cp -f sdb/src/.sdb${BUILD_EXT_EXE} $@
.PHONY: sdb-sync sync-sdb sdbclean
.PHONY: sdb-sync sync-sdb sdbclean sdb-native-build sdb-target-build
SDB_F=README.md config.mk src Makefile meson.build
SDB_SYNCFILES=$(addprefix sdb.vc/,${SDB_F})
I=../libr/include
@ -188,17 +192,13 @@ sdb-sync sync-sdb:
git clone --depth 1 ${SDB_URL} sdb.vc
mkdir -p sdb
cp -rf ${SDB_SYNCFILES} sdb
rm -rf sdb.vc $I/sdb
mkdir -p $I/sdb
rm -rf sdb.vc
rm -f src/sdb_version.h
cd sdb ; $(MAKE) src/sdb_version.h
cp -f sdb/src/*.h $I/sdb
echo '#include <sdb/sdb.h>' > $I/sdb.h
mkdir -p sdb/test sdb/memcache
sed -e 's,HAVE_VALA=,HAVE_VALA=#,' sdb/config.mk > .t
mv .t sdb/config.mk
echo all clean mrproper: | tee sdb/test/Makefile > sdb/memcache/Makefile
git add $I/sdb*
git add sdb
.PHONY: ptrace-wrap ptrace-wrap-sync sync-ptrace-wrap ptrace-wrap-clean clean-ptrace-wrap

View File

@ -31,6 +31,8 @@ LIBAR=libr_ar.${EXT_AR}
LDFLAGS+=-L../../libr/util
LIBS=-lr_util
include ../../shlr/sdb.mk
OFILES=ar.o
all: ${LIBAR}

View File

@ -26,6 +26,7 @@ endif
#OSTYPE=windows
include ../../libr/socket/deps.mk
include ../../shlr/zip/deps.mk
include ../../shlr/sdb.mk
SRC_D=src
SRC_C=$(wildcard $(SRC_D)/*.c)

View File

@ -32,6 +32,7 @@ endif
#OSTYPE=windows
include ../../libr/socket/deps.mk
include ../../shlr/sdb.mk
# Test variables
TEST_D= $(PWD)/test

View File

@ -83,6 +83,8 @@ ifeq (${OSTYPE},darwin)
CFLAGS+=-DAPPLE_CC
endif
include ../../shlr/sdb.mk
BIN=test${EXT_EXE}
all: ${KERNOBJS}

View File

@ -32,6 +32,8 @@ CFLAGS+=-I../../libr/include
LDFLAGS+=-L../../libr/util
OBJS=code.o class.o ops.o dsojson.o
include ../../shlr/sdb.mk
all: libr_java.$(EXT_AR)
RANLIB?=ranlib

View File

@ -154,90 +154,6 @@ else
endif
# handle sdb dependency
# NOTE: copying most of the stuff from sdb to here for the moment, since we
# should use subpackages to handle this well
sdb_files = [
'sdb/src/array.c',
'sdb/src/base64.c',
'sdb/src/buffer.c',
'sdb/src/set.c',
'sdb/src/cdb.c',
'sdb/src/cdb_make.c',
'sdb/src/dict.c',
'sdb/src/diff.c',
'sdb/src/disk.c',
'sdb/src/fmt.c',
'sdb/src/ht_uu.c',
'sdb/src/ht_up.c',
'sdb/src/ht_pp.c',
'sdb/src/journal.c',
'sdb/src/json.c',
'sdb/src/lock.c',
'sdb/src/ls.c',
# 'sdb/src/main.c',
'sdb/src/match.c',
'sdb/src/ns.c',
'sdb/src/num.c',
'sdb/src/query.c',
'sdb/src/sdb.c',
'sdb/src/sdbht.c',
'sdb/src/util.c'
]
sdb_inc = [platform_inc, include_directories('sdb/src')]
libr2sdb = static_library('r2sdb', sdb_files,
include_directories: sdb_inc,
implicit_include_directories: false,
c_args: host_machine.system() == 'windows' ? '-DSDB_API=__declspec(dllexport)' : [],
)
sdb_dep = declare_dependency(
link_whole: libr2sdb,
include_directories: sdb_inc
)
# Create sdb_version.h
r = run_command(py3_exe, 'sys/sdb_version.py', 'sdb/config.mk')
if r.returncode() == 0
sdb_version = r.stdout().strip().split('\n')[0]
else
sdb_version = 'unknown'
endif
run_command(py3_exe, '-c', 'with open("sdb/src/sdb_version.h", "w") as f: f.write("#define SDB_VERSION \"' + sdb_version + '\"")')
sdb_exe = executable('sdb', ['sdb/src/main.c'] + sdb_files,
include_directories: [
include_directories(['sdb/src'])
],
implicit_include_directories: false,
native: true,
)
sdb_gen_cmd_script = '''#script
import os
import sys
sdb_exe = r'@0@'
outfile = sys.argv[1]
infiles = sys.argv[2:]
if os.name == 'nt':
# DO NOT replace chr(92) below with a backslash
infiles, sdb_exe, outfile = map(lambda x: x.replace('/', chr(92)), [' '.join(infiles), sdb_exe, outfile])
os.system('type {} | {} {} ='.format(infiles, sdb_exe, outfile))
else:
infiles = ' '.join(infiles)
os.system('cat {} | {} {} ='.format(infiles, sdb_exe, outfile))
'''.format(sdb_exe.full_path())
sdb_gen_cmd = [
py3_exe,
'-c',
sdb_gen_cmd_script,
'@OUTPUT@',
'@INPUT@'
]
# handle tree-sitter
tree_sitter_dep = dependency('tree-sitter', required: false)
if not tree_sitter_dep.found() or not get_option('use_sys_tree_sitter')
@ -327,6 +243,7 @@ bochs_files = [
bochs_inc = [platform_inc, include_directories('bochs/include')]
libr2bochs = static_library('r2bochs', bochs_files,
dependencies: [r_util_dep],
include_directories: bochs_inc,
implicit_include_directories: false
)
@ -349,6 +266,7 @@ java_files = [
java_inc = [platform_inc, include_directories('java')]
libr2java = static_library('r2java', java_files,
dependencies: [r_util_dep],
include_directories: java_inc,
implicit_include_directories: false
)
@ -371,6 +289,7 @@ qnx_files = [
qnx_inc = [platform_inc, include_directories('qnx/include')]
libr2qnx = static_library('r2qnx', qnx_files,
dependencies: [r_socket_dep],
include_directories: qnx_inc,
implicit_include_directories: false
)
@ -391,6 +310,7 @@ tcc_files = [
tcc_inc = [platform_inc, include_directories('tcc')]
libr2tcc = static_library('r2tcc', tcc_files,
dependencies: [r_util_dep],
include_directories: tcc_inc,
implicit_include_directories: false
)
@ -401,25 +321,6 @@ tcc_dep = declare_dependency(
)
# handle spp dependency
spp_files = [
'spp/spp.c'
]
spp_inc = [platform_inc, include_directories('spp')]
libr2spp = static_library('r2spp', spp_files,
include_directories: spp_inc,
c_args: ['-DHAVE_R_UTIL', '-DUSE_R2=1'],
implicit_include_directories: false
)
spp_dep = declare_dependency(
link_with: libr2spp,
include_directories: spp_inc
)
# handle lz4 dependency
lz4_dep = dependency('liblz4', required: false)
if not lz4_dep.found() or not get_option('use_sys_lz4')
@ -444,45 +345,6 @@ else
endif
# handle zlib dependency
zlib_dep = dependency('zlib', required: false)
if not zlib_dep.found() or not get_option('use_sys_zlib')
message('Use bundled zlib')
zlib_files = [
'zip/zlib/adler32.c',
'zip/zlib/compress.c',
'zip/zlib/crc32.c',
'zip/zlib/deflate.c',
'zip/zlib/gzclose.c',
'zip/zlib/gzlib.c',
'zip/zlib/gzread.c',
'zip/zlib/gzwrite.c',
'zip/zlib/infback.c',
'zip/zlib/inffast.c',
'zip/zlib/inflate.c',
'zip/zlib/inftrees.c',
'zip/zlib/trees.c',
'zip/zlib/uncompr.c',
'zip/zlib/zutil.c'
]
zlib_inc = [platform_inc, include_directories('zip/zlib')]
libr2zlib = static_library('r2zlib', zlib_files,
include_directories: zlib_inc,
implicit_include_directories: false
)
zlib_dep = declare_dependency(
link_with: libr2zlib,
include_directories: zlib_inc
)
else
message('Use system-provided zlib library')
endif
# handle zip dependency
zip_dep = dependency('libzip', required: false)
if not zip_dep.found() or not get_option('use_sys_zip')
@ -646,6 +508,7 @@ grub_files = [
grub_inc = [platform_inc, include_directories('grub', 'grub/include')]
libr2grub = static_library('r2grub', grub_files,
dependencies: [r_util_dep],
include_directories: grub_inc,
implicit_include_directories: false
)
@ -667,6 +530,7 @@ windbg_files = [
windbg_inc = [platform_inc, include_directories('windbg')]
libr2windbg = static_library('r2windbg', windbg_files,
dependencies: [r_util_dep],
include_directories: windbg_inc,
implicit_include_directories: false
)
@ -685,6 +549,7 @@ ar_files = [
ar_inc = [platform_inc, include_directories(['ar'])]
libr2ar = static_library('r2ar', ar_files,
dependencies: [r_util_dep],
include_directories: ar_inc,
implicit_include_directories: false
)

View File

@ -26,6 +26,7 @@ LDFLAGS_SHARED=-shared
endif
#OSTYPE=windows
include ../../libr/socket/deps.mk
include ../../shlr/sdb.mk
# Test variables
TEST_D= $(PWD)/test

1
shlr/sdb.mk Normal file
View File

@ -0,0 +1 @@
CFLAGS+=-I$(SHLR)/sdb/src

View File

@ -1,3 +1,4 @@
include ../../libr/config.mk
include ../../config-user.mk
include ../../mk/platform.mk
include ../../mk/${COMPILER}.mk
@ -26,6 +27,8 @@ endif
endif
LIBNAME=libr_tcc.${SOEXT}
include ../../shlr/sdb.mk
all: ${LIBNAME} libr_tcc.$(EXT_AR)
${LIBNAME}: ${OFILES}

View File

@ -10,6 +10,8 @@ LIBAR=libr_windbg.${EXT_AR}
LDFLAGS+=-L../../libr/util
LIBS=-lr_util
include ../../shlr/sdb.mk
OFILES=transport.o kd.o windbg.o iob_pipe.o
all: ${LIBAR}

View File

@ -5,6 +5,7 @@ include ../../config-user.mk
include ../../libr/config.mk
include ../../mk/platform.mk
include ../../mk/$(COMPILER).mk
include ../../shlr/sdb.mk
ifeq ($(USE_LIB_ZIP),1)
all: