From 2d160f250918609fa8f399a33f003cedaa85d888 Mon Sep 17 00:00:00 2001 From: Riccardo Schirone Date: Tue, 21 Jul 2020 10:28:43 +0200 Subject: [PATCH] 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 --- Makefile | 2 +- binr/rules.mk | 2 + libr/Makefile | 3 +- libr/anal/block.c | 2 +- libr/anal/type.c | 2 +- libr/anal/type_dwarf.c | 2 +- libr/asm/meson.build | 1 - libr/bin/format/coff/coff.h | 2 +- libr/bin/format/pe/pe.c | 2 +- libr/bin/p/bin_coff.c | 2 +- libr/bin/p/bin_elf.inc | 2 +- libr/bin/p/bin_mach0.c | 2 +- libr/bin/p/bin_symbols.c | 2 +- libr/core/canal.c | 2 +- libr/core/cmd_debug.c | 2 +- libr/core/cmd_meta.c | 2 +- libr/core/cmd_search.c | 2 +- libr/core/cmd_type.c | 2 +- libr/core/meson.build | 1 - libr/include/r_anal.h | 2 +- libr/include/r_cons.h | 2 +- libr/include/r_util/r_event.h | 2 +- libr/include/r_util/r_str_constpool.h | 2 +- libr/include/sdb.h | 1 - libr/include/sdb/buffer.h | 57 ---- libr/include/sdb/cdb.h | 39 --- libr/include/sdb/cdb_make.h | 40 --- libr/include/sdb/config.h | 16 -- libr/include/sdb/dict.h | 50 ---- libr/include/sdb/ht_inc.h | 108 ------- libr/include/sdb/ht_pp.h | 16 -- libr/include/sdb/ht_up.h | 16 -- libr/include/sdb/ht_uu.h | 14 - libr/include/sdb/ls.h | 75 ----- libr/include/sdb/sdb.h | 390 -------------------------- libr/include/sdb/sdb_version.h | 1 - libr/include/sdb/sdbht.h | 52 ---- libr/include/sdb/set.h | 23 -- libr/include/sdb/types.h | 135 --------- libr/lang/meson.build | 2 +- libr/meson.build | 20 -- libr/rules.mk | 2 + libr/socket/meson.build | 3 +- libr/util/meson.build | 2 +- libr/util/sdb.mk | 2 +- meson.build | 164 ++++++++++- pkgcfg/r_util.pc.acr | 2 +- shlr/Makefile | 22 +- shlr/ar/Makefile | 2 + shlr/bochs/Makefile | 1 + shlr/gdb/Makefile | 1 + shlr/grub/Makefile | 2 + shlr/java/Makefile | 2 + shlr/meson.build | 149 +--------- shlr/qnx/Makefile | 1 + shlr/sdb.mk | 1 + shlr/tcc/Makefile | 3 + shlr/windbg/Makefile | 2 + shlr/zip/Makefile | 1 + 59 files changed, 227 insertions(+), 1235 deletions(-) delete mode 100644 libr/include/sdb.h delete mode 100644 libr/include/sdb/buffer.h delete mode 100644 libr/include/sdb/cdb.h delete mode 100644 libr/include/sdb/cdb_make.h delete mode 100644 libr/include/sdb/config.h delete mode 100644 libr/include/sdb/dict.h delete mode 100644 libr/include/sdb/ht_inc.h delete mode 100644 libr/include/sdb/ht_pp.h delete mode 100644 libr/include/sdb/ht_up.h delete mode 100644 libr/include/sdb/ht_uu.h delete mode 100644 libr/include/sdb/ls.h delete mode 100644 libr/include/sdb/sdb.h delete mode 100644 libr/include/sdb/sdb_version.h delete mode 100644 libr/include/sdb/sdbht.h delete mode 100644 libr/include/sdb/set.h delete mode 100644 libr/include/sdb/types.h create mode 100644 shlr/sdb.mk diff --git a/Makefile b/Makefile index 9188745297..5a1a7189d4 100644 --- a/Makefile +++ b/Makefile @@ -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" diff --git a/binr/rules.mk b/binr/rules.mk index 56fd9afe3d..4f57620d5c 100644 --- a/binr/rules.mk +++ b/binr/rules.mk @@ -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 diff --git a/libr/Makefile b/libr/Makefile index ca78076059..f74cd4cf7a 100644 --- a/libr/Makefile +++ b/libr/Makefile @@ -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}" \ diff --git a/libr/anal/block.c b/libr/anal/block.c index afd8b67840..ca52606d91 100644 --- a/libr/anal/block.c +++ b/libr/anal/block.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2019-2020 - pancake, thestr4ng3r */ #include -#include +#include #include diff --git a/libr/anal/type.c b/libr/anal/type.c index 8650f24662..0dba8c13fb 100644 --- a/libr/anal/type.c +++ b/libr/anal/type.c @@ -2,7 +2,7 @@ #include #include -#include "sdb/sdb.h" +#include static char *is_type(char *type) { char *name = NULL; diff --git a/libr/anal/type_dwarf.c b/libr/anal/type_dwarf.c index 1db78564a6..a728de3109 100644 --- a/libr/anal/type_dwarf.c +++ b/libr/anal/type_dwarf.c @@ -1,5 +1,5 @@ #include -#include "sdb/sdb.h" +#include #include #include diff --git a/libr/asm/meson.build b/libr/asm/meson.build index f217db722d..ca7ec81531 100644 --- a/libr/asm/meson.build +++ b/libr/asm/meson.build @@ -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, diff --git a/libr/bin/format/coff/coff.h b/libr/bin/format/coff/coff.h index 5766d2df49..554f48d2cb 100644 --- a/libr/bin/format/coff/coff.h +++ b/libr/bin/format/coff/coff.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include #define COFF_IS_BIG_ENDIAN 1 #define COFF_IS_LITTLE_ENDIAN 0 diff --git a/libr/bin/format/pe/pe.c b/libr/bin/format/pe/pe.c index 81fcae7e97..b3c2f9efbe 100644 --- a/libr/bin/format/pe/pe.c +++ b/libr/bin/format/pe/pe.c @@ -8,7 +8,7 @@ #include #include "pe.h" #include -#include +#include #define PE_IMAGE_FILE_MACHINE_RPI2 452 #define MAX_METADATA_STRING_LENGTH 256 diff --git a/libr/bin/p/bin_coff.c b/libr/bin/p/bin_coff.c index 0de511aed1..a27fc8196a 100644 --- a/libr/bin/p/bin_coff.c +++ b/libr/bin/p/bin_coff.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include "coff/coff.h" diff --git a/libr/bin/p/bin_elf.inc b/libr/bin/p/bin_elf.inc index 084828da0a..b6a1e226d6 100644 --- a/libr/bin/p/bin_elf.inc +++ b/libr/bin/p/bin_elf.inc @@ -9,7 +9,7 @@ #include #include "../i/private.h" #include "elf/elf.h" -#include +#include static RBinInfo* info(RBinFile *bf); diff --git a/libr/bin/p/bin_mach0.c b/libr/bin/p/bin_mach0.c index bbbbccc057..6b6a7d8013 100644 --- a/libr/bin/p/bin_mach0.c +++ b/libr/bin/p/bin_mach0.c @@ -8,7 +8,7 @@ #include "../i/private.h" #include "mach0/mach0.h" #include "objc/mach0_classes.h" -#include +#include // wip settings diff --git a/libr/bin/p/bin_symbols.c b/libr/bin/p/bin_symbols.c index bae0ea6362..855cd84904 100644 --- a/libr/bin/p/bin_symbols.c +++ b/libr/bin/p/bin_symbols.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include "../i/private.h" #include "mach0/coresymbolication.h" diff --git a/libr/core/canal.c b/libr/core/canal.c index 51d44a5417..192a5d2bd6 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include diff --git a/libr/core/cmd_debug.c b/libr/core/cmd_debug.c index 9788939790..f09d0257e3 100644 --- a/libr/core/cmd_debug.c +++ b/libr/core/cmd_debug.c @@ -2,7 +2,7 @@ #include #include -#include +#include #define TN_KEY_LEN 32 #define TN_KEY_FMT "%"PFMT64u #ifndef SIGKILL diff --git a/libr/core/cmd_meta.c b/libr/core/cmd_meta.c index 7ccb6fb3e0..0c975f3192 100644 --- a/libr/core/cmd_meta.c +++ b/libr/core/cmd_meta.c @@ -6,7 +6,7 @@ #include "r_core.h" #include "r_util.h" #include "r_types.h" -#include "sdb/sdb.h" +#include char *getcommapath(RCore *core); diff --git a/libr/core/cmd_search.c b/libr/core/cmd_search.c index 1c7291931c..cf895f2c78 100644 --- a/libr/core/cmd_search.c +++ b/libr/core/cmd_search.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2010-2019 - pancake */ -#include +#include #include #include #include "r_io.h" diff --git a/libr/core/cmd_type.c b/libr/core/cmd_type.c index 4232edd828..48732b0a44 100644 --- a/libr/core/cmd_type.c +++ b/libr/core/cmd_type.c @@ -4,7 +4,7 @@ #include "r_anal.h" #include "r_cons.h" #include "r_core.h" -#include "sdb/sdb.h" +#include static const char *help_msg_t[] = { "Usage: t", "", "# cparse types commands", diff --git a/libr/core/meson.build b/libr/core/meson.build index 0299bd4b3b..55dbc152cd 100644 --- a/libr/core/meson.build +++ b/libr/core/meson.build @@ -100,7 +100,6 @@ r_core_deps = [ r_asm_dep, r_bp_dep, platform_deps, - spp_dep, gdb_dep, java_dep, shell_parser_dep diff --git a/libr/include/r_anal.h b/libr/include/r_anal.h index 1dfe00ffde..db6638a356 100644 --- a/libr/include/r_anal.h +++ b/libr/include/r_anal.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include diff --git a/libr/include/r_cons.h b/libr/include/r_cons.h index dd9cb08fba..c857da1103 100644 --- a/libr/include/r_cons.h +++ b/libr/include/r_cons.h @@ -21,7 +21,7 @@ extern "C" { #include #include #include -#include +#include #include #include diff --git a/libr/include/r_util/r_event.h b/libr/include/r_util/r_event.h index b2eae5a9f2..f2dd52cca3 100644 --- a/libr/include/r_util/r_event.h +++ b/libr/include/r_util/r_event.h @@ -7,7 +7,7 @@ extern "C" { #endif -#include +#include #include typedef struct r_event_t { diff --git a/libr/include/r_util/r_str_constpool.h b/libr/include/r_util/r_str_constpool.h index 9b88783191..cec9a56e90 100644 --- a/libr/include/r_util/r_str_constpool.h +++ b/libr/include/r_util/r_str_constpool.h @@ -2,7 +2,7 @@ #define R_STR_CONSTPOOL_H #include -#include +#include #include diff --git a/libr/include/sdb.h b/libr/include/sdb.h deleted file mode 100644 index c78d0c0283..0000000000 --- a/libr/include/sdb.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/libr/include/sdb/buffer.h b/libr/include/sdb/buffer.h deleted file mode 100644 index 4fd4bf61fc..0000000000 --- a/libr/include/sdb/buffer.h +++ /dev/null @@ -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 diff --git a/libr/include/sdb/cdb.h b/libr/include/sdb/cdb.h deleted file mode 100644 index b0d71d9ad6..0000000000 --- a/libr/include/sdb/cdb.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Public domain. */ - -#ifndef CDB_H -#define CDB_H - -#include -#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 diff --git a/libr/include/sdb/cdb_make.h b/libr/include/sdb/cdb_make.h deleted file mode 100644 index 45c3c35925..0000000000 --- a/libr/include/sdb/cdb_make.h +++ /dev/null @@ -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 diff --git a/libr/include/sdb/config.h b/libr/include/sdb/config.h deleted file mode 100644 index 7eaa88c7d9..0000000000 --- a/libr/include/sdb/config.h +++ /dev/null @@ -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 diff --git a/libr/include/sdb/dict.h b/libr/include/sdb/dict.h deleted file mode 100644 index 7dfd2aeec9..0000000000 --- a/libr/include/sdb/dict.h +++ /dev/null @@ -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); diff --git a/libr/include/sdb/ht_inc.h b/libr/include/sdb/ht_inc.h deleted file mode 100644 index 892f4977f4..0000000000 --- a/libr/include/sdb/ht_inc.h +++ /dev/null @@ -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); diff --git a/libr/include/sdb/ht_pp.h b/libr/include/sdb/ht_pp.h deleted file mode 100644 index c2d1b4d33b..0000000000 --- a/libr/include/sdb/ht_pp.h +++ /dev/null @@ -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 diff --git a/libr/include/sdb/ht_up.h b/libr/include/sdb/ht_up.h deleted file mode 100644 index ebc2333f0f..0000000000 --- a/libr/include/sdb/ht_up.h +++ /dev/null @@ -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 diff --git a/libr/include/sdb/ht_uu.h b/libr/include/sdb/ht_uu.h deleted file mode 100644 index ee042a6383..0000000000 --- a/libr/include/sdb/ht_uu.h +++ /dev/null @@ -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 diff --git a/libr/include/sdb/ls.h b/libr/include/sdb/ls.h deleted file mode 100644 index 70e2e96ceb..0000000000 --- a/libr/include/sdb/ls.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef LS_H -#define LS_H - -#include -#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 diff --git a/libr/include/sdb/sdb.h b/libr/include/sdb/sdb.h deleted file mode 100644 index f845c5043e..0000000000 --- a/libr/include/sdb/sdb.h +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#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 -#include -#include // 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 diff --git a/libr/include/sdb/sdb_version.h b/libr/include/sdb/sdb_version.h deleted file mode 100644 index 1af4f2266b..0000000000 --- a/libr/include/sdb/sdb_version.h +++ /dev/null @@ -1 +0,0 @@ -#define SDB_VERSION "1.4.1" diff --git a/libr/include/sdb/sdbht.h b/libr/include/sdb/sdbht.h deleted file mode 100644 index 6e8da12568..0000000000 --- a/libr/include/sdb/sdbht.h +++ /dev/null @@ -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 diff --git a/libr/include/sdb/set.h b/libr/include/sdb/set.h deleted file mode 100644 index 187664dbf2..0000000000 --- a/libr/include/sdb/set.h +++ /dev/null @@ -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 diff --git a/libr/include/sdb/types.h b/libr/include/sdb/types.h deleted file mode 100644 index bef7af8b00..0000000000 --- a/libr/include/sdb/types.h +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef TYPES_H -#define TYPES_H - -#include -#include -#include -#include -#include -#include - -#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 -#include -#else -// CYGWIN AND UNIX -#define __SDB_WINDOWS__ 0 -#define DIRSEP '/' -#include -#endif - -#include -#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 diff --git a/libr/lang/meson.build b/libr/lang/meson.build index 6cbf565a6b..6b0e73bdd5 100644 --- a/libr/lang/meson.build +++ b/libr/lang/meson.build @@ -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 diff --git a/libr/meson.build b/libr/meson.build index cacbed04f9..afa63da320 100644 --- a/libr/meson.build +++ b/libr/meson.build @@ -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' diff --git a/libr/rules.mk b/libr/rules.mk index 427aa375ad..2e83c14929 100644 --- a/libr/rules.mk +++ b/libr/rules.mk @@ -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 diff --git a/libr/socket/meson.build b/libr/socket/meson.build index 2e0f886343..2f74c6070b 100644 --- a/libr/socket/meson.build +++ b/libr/socket/meson.build @@ -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', diff --git a/libr/util/meson.build b/libr/util/meson.build index daaf89fa87..449d59e116 100644 --- a/libr/util/meson.build +++ b/libr/util/meson.build @@ -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', diff --git a/libr/util/sdb.mk b/libr/util/sdb.mk index 6a3b50e203..1264ec514d 100644 --- a/libr/util/sdb.mk +++ b/libr/util/sdb.mk @@ -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 diff --git a/meson.build b/meson.build index 3508a9703d..6d0386c79c 100644 --- a/meson.build +++ b/meson.build @@ -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') diff --git a/pkgcfg/r_util.pc.acr b/pkgcfg/r_util.pc.acr index aa4f3cb60b..387d4677ee 100644 --- a/pkgcfg/r_util.pc.acr +++ b/pkgcfg/r_util.pc.acr @@ -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 diff --git a/shlr/Makefile b/shlr/Makefile index 9521ce4c0b..ba3af6a73e 100644 --- a/shlr/Makefile +++ b/shlr/Makefile @@ -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 ' > $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 diff --git a/shlr/ar/Makefile b/shlr/ar/Makefile index a79a7c964b..33312db62d 100644 --- a/shlr/ar/Makefile +++ b/shlr/ar/Makefile @@ -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} diff --git a/shlr/bochs/Makefile b/shlr/bochs/Makefile index f667cab703..702dd311a2 100644 --- a/shlr/bochs/Makefile +++ b/shlr/bochs/Makefile @@ -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) diff --git a/shlr/gdb/Makefile b/shlr/gdb/Makefile index f7ebaeed48..c68ad1042a 100644 --- a/shlr/gdb/Makefile +++ b/shlr/gdb/Makefile @@ -32,6 +32,7 @@ endif #OSTYPE=windows include ../../libr/socket/deps.mk +include ../../shlr/sdb.mk # Test variables TEST_D= $(PWD)/test diff --git a/shlr/grub/Makefile b/shlr/grub/Makefile index 8504266aa4..ae121e8243 100644 --- a/shlr/grub/Makefile +++ b/shlr/grub/Makefile @@ -83,6 +83,8 @@ ifeq (${OSTYPE},darwin) CFLAGS+=-DAPPLE_CC endif +include ../../shlr/sdb.mk + BIN=test${EXT_EXE} all: ${KERNOBJS} diff --git a/shlr/java/Makefile b/shlr/java/Makefile index d056725b20..79831d1a58 100644 --- a/shlr/java/Makefile +++ b/shlr/java/Makefile @@ -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 diff --git a/shlr/meson.build b/shlr/meson.build index 2b643a14dd..48dfaf1ea8 100644 --- a/shlr/meson.build +++ b/shlr/meson.build @@ -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 ) diff --git a/shlr/qnx/Makefile b/shlr/qnx/Makefile index 8b23f68c8b..669b31f01a 100644 --- a/shlr/qnx/Makefile +++ b/shlr/qnx/Makefile @@ -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 diff --git a/shlr/sdb.mk b/shlr/sdb.mk new file mode 100644 index 0000000000..646fbb07f3 --- /dev/null +++ b/shlr/sdb.mk @@ -0,0 +1 @@ +CFLAGS+=-I$(SHLR)/sdb/src diff --git a/shlr/tcc/Makefile b/shlr/tcc/Makefile index 9673ffac2a..e461392c89 100644 --- a/shlr/tcc/Makefile +++ b/shlr/tcc/Makefile @@ -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} diff --git a/shlr/windbg/Makefile b/shlr/windbg/Makefile index 026d6f49a4..9220e82b7e 100644 --- a/shlr/windbg/Makefile +++ b/shlr/windbg/Makefile @@ -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} diff --git a/shlr/zip/Makefile b/shlr/zip/Makefile index 47ddf96a76..9b5304d53e 100644 --- a/shlr/zip/Makefile +++ b/shlr/zip/Makefile @@ -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: