forestdb.lib: use returned length since strings dont seem to be null terminated.

db4
Doug Coleman 2014-11-04 00:39:05 -08:00
parent d5834dd7c6
commit e5ee876dc5
1 changed files with 8 additions and 8 deletions

View File

@ -1,8 +1,8 @@
! Copyright (C) 2014 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data alien.strings
combinators destructors forestdb.ffi fry io.pathnames kernel
libc namespaces sequences ;
combinators destructors forestdb.ffi fry io.encodings.string
io.encodings.utf8 io.pathnames kernel libc namespaces sequences ;
IN: forestdb.lib
ERROR: fdb-error error ;
@ -36,17 +36,17 @@ SYMBOL: current-forestdb
[ get-handle ] 2dip
[ dup length ] bi@ fdb_set_kv check-forestdb-error ;
: ret>string ( void** -- string )
void* deref
[ alien>native-string ] [ (free) ] bi ;
: ret>string ( void** len -- string )
[ void* deref ] [ size_t deref ] bi*
[ memory>byte-array utf8 decode ] [ drop (free) ] 2bi ;
: fdb-get ( key -- value/f )
[ get-handle ] dip
dup length f void* <ref> 0 size_t <ref>
[ fdb_get_kv ] 2keep drop
swap {
[ fdb_get_kv ] 2keep
rot {
{ FDB_RESULT_SUCCESS [ ret>string ] }
{ FDB_RESULT_KEY_NOT_FOUND [ drop f ] }
{ FDB_RESULT_KEY_NOT_FOUND [ 2drop f ] }
[ fdb-error ]
} case ;