]> gitweb.factorcode.org Git - factor.git/commitdiff
gdbm: implement gdbm-setopt
authorDmitry Shubin <dmitry.sh@gmail.com>
Wed, 16 Jun 2010 23:51:28 +0000 (03:51 +0400)
committerDmitry Shubin <dmitry.sh@gmail.com>
Wed, 16 Jun 2010 23:51:28 +0000 (03:51 +0400)
extra/gdbm/gdbm.factor

index 28aa9b35f28d142aed21efba540ffff3935f2530..2f052a3872d578b01600d3aea1c6df8d5cacf55b 100644 (file)
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien.c-types alien.data alien.destructors assocs
 biassocs classes.struct combinators destructors gdbm.ffi io.backend
-kernel libc literals math namespaces sequences serialize strings ;
+kernel libc literals locals math namespaces sequences serialize
+strings ;
 IN: gdbm
 
 TUPLE: gdbm
@@ -125,7 +126,19 @@ PRIVATE>
     [ dbf swap object>datum gdbm_exists c-bool> ]
     with-destructors ;
 
-! : gdbm-setopt ( option value size -- ret ) ;
+<PRIVATE
+
+:: (gdbm-setopt) ( option value -- )
+    [
+        int heap-size dup malloc &free :> ( size ptr )
+        value ptr 0 int set-alien-value
+        dbf option ptr size gdbm_setopt check-error
+    ] with-destructors ;
+
+PRIVATE>
+
+: gdbm-setopt ( option value -- )
+    over GDBM_CACHESIZE = [ >c-bool ] unless (gdbm-setopt) ;
 
 : gdbm-fdesc ( -- desc ) dbf gdbm_fdesc ;