From 25dceb21a8b25e3197650daa62e58972de6ec62e Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 21 Jul 2009 22:59:34 +0000 Subject: [PATCH] * Initial vapi for r_db - Added vala example using r_db (db.vala) * Fix segmentation fault in db.c when adding nodes with no keys defined. (-1) * Added vala example * Added r_db to the default build list * Added r_th, r_bp and r_db in pkgconfig --- configure | 2 +- configure.acr | 3 +++ libr/Makefile | 2 +- libr/db/Makefile | 1 + libr/db/TODO | 4 ++++ libr/db/db.c | 14 +++++++++----- libr/pkgconfig/libr.pc.acr | 11 +++++++++++ libr/vapi/r_asm.vapi | 1 + libr/vapi/r_db.vapi | 23 +++++++++++++++++++++++ libr/vapi/t/Makefile | 5 ++++- libr/vapi/t/db.vala | 17 +++++++++++++++++ pkgcfg/libr.pc.acr | 2 +- pkgcfg/r_bp.pc.acr | 11 +++++++++++ pkgcfg/r_db.pc.acr | 11 +++++++++++ pkgcfg/r_th.pc.acr | 11 +++++++++++ 15 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 libr/pkgconfig/libr.pc.acr create mode 100644 libr/vapi/r_db.vapi create mode 100644 libr/vapi/t/db.vala create mode 100644 pkgcfg/r_bp.pc.acr create mode 100644 pkgcfg/r_db.pc.acr create mode 100644 pkgcfg/r_th.pc.acr diff --git a/configure b/configure index 372c647a85..1e4363940a 100755 --- a/configure +++ b/configure @@ -368,7 +368,7 @@ for A in ${ENVWORDS} ; do SEDFLAGS="${SEDFLAGS}s,@${A}@,${VAR},g;" done SEDFLAGS="${SEDFLAGS}'" -for A in ./config-user.mk libr/include/r_userconf.h pkgcfg/libr.pc pkgcfg/r_io.pc pkgcfg/r_asm.pc pkgcfg/r_bin.pc pkgcfg/r_cons.pc pkgcfg/r_diff.pc pkgcfg/r_core.pc pkgcfg/r_socket.pc pkgcfg/r_line.pc pkgcfg/r_syscall.pc pkgcfg/r_macro.pc pkgcfg/r_util.pc pkgcfg/r_search.pc pkgcfg/r_vm.pc ; do # SUBDIRS +for A in ./config-user.mk libr/include/r_userconf.h pkgcfg/libr.pc pkgcfg/r_io.pc pkgcfg/r_asm.pc pkgcfg/r_bin.pc pkgcfg/r_cons.pc pkgcfg/r_diff.pc pkgcfg/r_core.pc pkgcfg/r_socket.pc pkgcfg/r_line.pc pkgcfg/r_syscall.pc pkgcfg/r_macro.pc pkgcfg/r_util.pc pkgcfg/r_search.pc pkgcfg/r_vm.pc pkgcfg/r_th.pc pkgcfg/r_bp.pc pkgcfg/r_db.pc ; do # SUBDIRS if [ -f "${VPATH}/${A}.acr" ]; then SD_TARGET=${A} else diff --git a/configure.acr b/configure.acr index 6ae4a544de..4e4c7818bd 100644 --- a/configure.acr +++ b/configure.acr @@ -50,4 +50,7 @@ SUBDIRS ./config-user.mk libr/include/r_userconf.h pkgcfg/r_util.pc pkgcfg/r_search.pc pkgcfg/r_vm.pc + pkgcfg/r_th.pc + pkgcfg/r_bp.pc + pkgcfg/r_db.pc ; diff --git a/libr/Makefile b/libr/Makefile index 181fb435a2..5b8d3ef6fc 100644 --- a/libr/Makefile +++ b/libr/Makefile @@ -5,7 +5,7 @@ PFX=${DESTDIR}${PREFIX} #PREFIX=${PFX} # Libraries -LIBLIST=io util lib meta lang flags bin bininfo macro hash line cons print config syscall range socket cmd asm anal parse search diff bp debug reg core var sign trace vm th +LIBLIST=io util lib meta lang flags bin bininfo macro hash line cons print config syscall range socket cmd asm anal parse search diff bp debug reg core var sign trace vm th db # Under development #LIBLIST+=print diff --git a/libr/db/Makefile b/libr/db/Makefile index 27f5219d7d..699d4bee82 100644 --- a/libr/db/Makefile +++ b/libr/db/Makefile @@ -1,4 +1,5 @@ NAME=r_db +DEPS=r_util OBJ=db.o table.o diff --git a/libr/db/TODO b/libr/db/TODO index 8741e7ccf3..4ca8adb27c 100644 --- a/libr/db/TODO +++ b/libr/db/TODO @@ -1,3 +1,7 @@ +* Return FALSE when adding two elements with the same + attributes (get before add) if the db is unique + // not necessary, we can just do this by manually checkingc + * Benchmarking - Compilation support for profiling memory usage - Compare performance against sqlite diff --git a/libr/db/db.c b/libr/db/db.c index 3f54cc2497..f6580de8eb 100644 --- a/libr/db/db.c +++ b/libr/db/db.c @@ -50,8 +50,12 @@ R_API int r_db_add_id(struct r_db_t *db, int key, int size) static int _r_db_add_internal(struct r_db_t *db, int key, void *b) { - int i, idx, len, size = db->blocks_sz[key]; - struct r_db_block_t *block = db->blocks[key]; + int i, idx, len, size; + struct r_db_block_t *block; + if (key<0 || key>255) + return R_FALSE; + size = db->blocks_sz[key]; + block = db->blocks[key]; if (block == NULL) { block = r_db_block_new(); db->blocks[key] = block; @@ -63,7 +67,7 @@ static int _r_db_add_internal(struct r_db_t *db, int key, void *b) block = block->childs[idx]; } if (block) { - if (block->data==NULL) { + if (block->data == NULL) { block->data = malloc(sizeof(void *)*2); block->data[0] = b; block->data[1] = NULL; @@ -75,12 +79,12 @@ static int _r_db_add_internal(struct r_db_t *db, int key, void *b) block->data[len+1] = NULL; } } - return (block!=NULL);; + return (block!=NULL); } R_API int r_db_add(struct r_db_t *db, void *b) { - int i, ret=0; + int i, ret = R_FALSE; for(i=db->id_min;i<=db->id_max;i++) { if (db->blocks[i]) ret += _r_db_add_internal(db, i, b); diff --git a/libr/pkgconfig/libr.pc.acr b/libr/pkgconfig/libr.pc.acr new file mode 100644 index 0000000000..129f626ad2 --- /dev/null +++ b/libr/pkgconfig/libr.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: libr +Description: radare framework libraries +Version: 0.1 +Requires: +Libs: -L${libdir} -lr_core -lr_lang -lr_search -lr_cmd -lr_meta -lr_asm -lr_util +Cflags: -I${includedir}/libr diff --git a/libr/vapi/r_asm.vapi b/libr/vapi/r_asm.vapi index 04e1ecc4dd..404882b393 100644 --- a/libr/vapi/r_asm.vapi +++ b/libr/vapi/r_asm.vapi @@ -75,6 +75,7 @@ namespace Radare { public uint64 mdisassemble(out Aop aop, uint8 *buf, uint64 length); public int massemble(out Aop aop, string buf); public int parse(); + // This is the destructor public void free(); } diff --git a/libr/vapi/r_db.vapi b/libr/vapi/r_db.vapi new file mode 100644 index 0000000000..014cb2dcef --- /dev/null +++ b/libr/vapi/r_db.vapi @@ -0,0 +1,23 @@ +/* radare - LGPL - Copyright 2009 pancake<@nopcode.org> */ + +[CCode (cheader_filename="r_db.h", cprefix="r_db_", lower_case_cprefix="r_db_")] +namespace Radare { + [Compact] + [CCode (cname="struct r_db_t", free_function="r_db_free", cprefix="r_db_")] + public class Database { + /* lifecycle */ + public Database(); + public void init(); + public void free(); + + /* storage */ + public int add_id(int off, int size); + public bool @add(void *b); + public bool delete(void *b); + public void* get(int key, uint8* buf); + + /* stacky! */ + public int push(ref uint8* buf); + public uint8 *pop(); + } +} diff --git a/libr/vapi/t/Makefile b/libr/vapi/t/Makefile index 5e47ccc1b4..a9e52e1370 100644 --- a/libr/vapi/t/Makefile +++ b/libr/vapi/t/Makefile @@ -1,10 +1,13 @@ -all: core hash sc socket asm search bin +all: core hash sc socket asm search bin db @true genie: valac --vapidir=.. --pkg r_asm --pkg libr asm.gs valac --vapidir=.. --pkg r_search --pkg libr search.gs +db: + valac --vapidir=${PWD}/.. --pkg r_db db.vala + sc: valac -C --vapidir=${PWD}/.. sc.vala --pkg r_syscall gcc sc.c `pkg-config gobject-2.0 --libs --cflags` -I../../include/ -lr_syscall -Wl,-R../../syscall -L../../syscall -o sc diff --git a/libr/vapi/t/db.vala b/libr/vapi/t/db.vala new file mode 100644 index 0000000000..07e9d544b1 --- /dev/null +++ b/libr/vapi/t/db.vala @@ -0,0 +1,17 @@ +using Radare; + +void main() +{ + int ret; + var db = new Radare.Database(); + db.add_id(0, 4); + + db.add("food"); + db.add("caca"); + db.add("food"); + + stdout.printf("%p\n", db.get(0, "caca")); + stdout.printf("%p\n", db.get(0, "miau")); + stdout.printf("%p\n", db.get(0, "food")); + db = null; +} diff --git a/pkgcfg/libr.pc.acr b/pkgcfg/libr.pc.acr index 9671ef8eb8..07071c0b6f 100644 --- a/pkgcfg/libr.pc.acr +++ b/pkgcfg/libr.pc.acr @@ -7,5 +7,5 @@ Name: libr Description: radare foundation libraries Version: 0.2 Requires: -Libs: -L${libdir} -lr_io -lr_util -lr_lib -lr_meta -lr_lang -lr_flags -lr_bin -lr_bininfo -lr_macro -lr_hash -lr_line -lr_cons -lr_print -lr_config -lr_syscall -lr_range -lr_socket -lr_cmd -lr_asm -lr_anal -lr_parse -lr_search -lr_diff -lr_bp -lr_debug -lr_reg -lr_core -lr_var -lr_sign -lr_trace -lr_vm +Libs: -L${libdir} -lr_io -lr_util -lr_lib -lr_meta -lr_lang -lr_flags -lr_bin -lr_bininfo -lr_macro -lr_hash -lr_line -lr_cons -lr_print -lr_config -lr_syscall -lr_range -lr_socket -lr_cmd -lr_asm -lr_anal -lr_parse -lr_search -lr_diff -lr_bp -lr_debug -lr_reg -lr_core -lr_var -lr_sign -lr_trace -lr_vm -lr_th -lr_db Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_bp.pc.acr b/pkgcfg/r_bp.pc.acr new file mode 100644 index 0000000000..8373500ad6 --- /dev/null +++ b/pkgcfg/r_bp.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: r_bp +Description: radare foundation libraries +Version: 0.2 +Requires: +Libs: -L${libdir} -lr_bp +Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_db.pc.acr b/pkgcfg/r_db.pc.acr new file mode 100644 index 0000000000..a3807a7c18 --- /dev/null +++ b/pkgcfg/r_db.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: r_db +Description: radare foundation libraries +Version: +Requires: +Libs: -L${libdir} -lr_db -lr_util +Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_th.pc.acr b/pkgcfg/r_th.pc.acr new file mode 100644 index 0000000000..13b3041577 --- /dev/null +++ b/pkgcfg/r_th.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: r_th +Description: radare foundation libraries +Version: +Requires: +Libs: -L${libdir} -lr_th +Cflags: -I${includedir}/libr