Permalink
Browse files

newer version of FFI have bool type. Adapted. Closes gh-23

  • Loading branch information...
1 parent fb10d34 commit b70a7dd2d188596f65ed169b5998777aa308fd66 @jmettraux committed Nov 16, 2009
View
@@ -2,6 +2,11 @@
= rufus-tokyo CHANGELOG.txt
+== rufus-tokyo - 1.0.3 not yet released
+
+- bug : newer versions of FFI have [undocumented] bool type. Adapted.
+
+
== rufus-tokyo - 1.0.2 released 2009/11/01
- bug : HashMethods#to_a not working right with Ruby 1.9.1. Fixed.
@@ -217,7 +217,7 @@ def initialize (name, params={})
name = name + params.collect { |k, v| "##{k}=#{v}" }.join('')
- (lib.tcadbopen(@db, name) != 0) || raise(
+ lib.tcadbopen(@db, name) || raise(
TokyoError.new("failed to open/create db '#{name}' #{params.inspect}"))
#
@@ -273,8 +273,7 @@ def putkeep (k, v)
k = k.to_s; v = v.to_s
- (lib.abs_putkeep(
- @db, k, Rufus::Tokyo.blen(k), v, Rufus::Tokyo.blen(v)) == 1)
+ lib.abs_putkeep(@db, k, Rufus::Tokyo.blen(k), v, Rufus::Tokyo.blen(v))
end
# Appends the given string at the end of the current string value for key k.
@@ -286,8 +285,7 @@ def putcat (k, v)
k = k.to_s; v = v.to_s
- (lib.abs_putcat(
- @db, k, Rufus::Tokyo.blen(k), v, Rufus::Tokyo.blen(v)) == 1)
+ lib.abs_putcat(@db, k, Rufus::Tokyo.blen(k), v, Rufus::Tokyo.blen(v))
end
# (The actual #[] method is provided by HashMethods
@@ -309,7 +307,7 @@ def delete (k)
v = self[k]
- (lib.abs_out(@db, k, Rufus::Tokyo.blen(k)) == 1) ? v : nil
+ lib.abs_out(@db, k, Rufus::Tokyo.blen(k)) ? v : nil
end
# Returns the number of records in the 'cabinet'
@@ -345,7 +343,7 @@ def close
result = lib.abs_close(@db)
lib.abs_del(@db)
- (result == 1)
+ result
end
# Copies the current cabinet to a new file.
@@ -354,7 +352,7 @@ def close
#
def copy (target_path)
- (lib.abs_copy(@db, target_path) == 1)
+ lib.abs_copy(@db, target_path)
end
# Copies the current cabinet to a new file.
@@ -374,7 +372,7 @@ def compact_copy (target_path)
#
def sync
- (lib.abs_sync(@db) == 1)
+ lib.abs_sync(@db)
end
# Returns an array with all the keys in the databse
@@ -641,7 +639,7 @@ def do_call_misc (function, list_pointer)
def libcall (lib_method, *args)
raise TokyoError.new("call to #{lib_method} failed") \
- unless lib.send(lib_method, @db, *args) == 1
+ unless lib.send(lib_method, @db, *args)
end
end
@@ -69,34 +69,34 @@ class << self
#
# tcadb functions
#
- # http://tokyocabinet.sourceforge.net/spex-en.html#tcadbapi
+ # http://1978th.net/tokyocabinet/spex-en.html#tcadbapi
attfunc :tcadbnew, [], :pointer
- attfunc :tcadbopen, [ :pointer, :string ], :int
- attfunc :abs_close, :tcadbclose, [ :pointer ], :int
+ attfunc :tcadbopen, [ :pointer, :string ], :bool
+ attfunc :abs_close, :tcadbclose, [ :pointer ], :bool
attfunc :abs_del, :tcadbdel, [ :pointer ], :void
attfunc :abs_rnum, :tcadbrnum, [ :pointer ], :uint64
attfunc :abs_size, :tcadbsize, [ :pointer ], :uint64
- attfunc :abs_put, :tcadbput, [ :pointer, :pointer, :int, :pointer, :int ], :int
+ attfunc :abs_put, :tcadbput, [ :pointer, :pointer, :int, :pointer, :int ], :bool
attfunc :abs_get, :tcadbget, [ :pointer, :pointer, :int, :pointer ], :pointer
- attfunc :abs_out, :tcadbout, [ :pointer, :pointer, :int ], :int
+ attfunc :abs_out, :tcadbout, [ :pointer, :pointer, :int ], :bool
- attfunc :abs_putkeep, :tcadbputkeep, [ :pointer, :pointer, :int, :pointer, :int ], :int
- attfunc :abs_putcat, :tcadbputcat, [ :pointer, :pointer, :int, :pointer, :int ], :int
+ attfunc :abs_putkeep, :tcadbputkeep, [ :pointer, :pointer, :int, :pointer, :int ], :bool
+ attfunc :abs_putcat, :tcadbputcat, [ :pointer, :pointer, :int, :pointer, :int ], :bool
- attfunc :abs_iterinit, :tcadbiterinit, [ :pointer ], :int
+ attfunc :abs_iterinit, :tcadbiterinit, [ :pointer ], :bool
attfunc :abs_iternext, :tcadbiternext, [ :pointer, :pointer ], :pointer
- attfunc :abs_vanish, :tcadbvanish, [ :pointer ], :int
+ attfunc :abs_vanish, :tcadbvanish, [ :pointer ], :bool
- attfunc :abs_sync, :tcadbsync, [ :pointer ], :int
- attfunc :abs_copy, :tcadbcopy, [ :pointer, :string ], :int
+ attfunc :abs_sync, :tcadbsync, [ :pointer ], :bool
+ attfunc :abs_copy, :tcadbcopy, [ :pointer, :string ], :bool
attfunc :abs_fwmkeys, :tcadbfwmkeys, [ :pointer, :pointer, :int, :int ], :pointer
@@ -108,41 +108,41 @@ class << self
attfunc :tcadbreveal, [ :pointer ], :pointer
# since TC 1.4.13
- attfunc :tcadbtranbegin, [ :pointer ], :int
- attfunc :tcadbtrancommit, [ :pointer ], :int
- attfunc :tcadbtranabort, [ :pointer ], :int
+ attfunc :tcadbtranbegin, [ :pointer ], :bool
+ attfunc :tcadbtrancommit, [ :pointer ], :bool
+ attfunc :tcadbtranabort, [ :pointer ], :bool
#
# tctdb functions
#
- # http://tokyocabinet.sourceforge.net/spex-en.html#tctdbapi
+ # http://1978th.net/tokyocabinet/spex-en.html#tctdbapi
attfunc :tctdbnew, [], :pointer
- attfunc :tctdbsetmutex, [ :pointer ], :int
- attfunc :tctdbtune, [ :pointer, :uint64, :uint8, :uint8, :uint8 ], :int
- attfunc :tctdbsetcache, [ :pointer, :uint32, :uint32, :uint32 ], :int
- attfunc :tctdbsetxmsiz, [ :pointer, :uint64 ], :int
+ attfunc :tctdbsetmutex, [ :pointer ], :bool
+ attfunc :tctdbtune, [ :pointer, :uint64, :uint8, :uint8, :uint8 ], :bool
+ attfunc :tctdbsetcache, [ :pointer, :uint32, :uint32, :uint32 ], :bool
+ attfunc :tctdbsetxmsiz, [ :pointer, :uint64 ], :bool
# since TC 1.4.21
- attfunc :tctdbsetdfunit, [ :pointer, :uint32 ], :int
+ attfunc :tctdbsetdfunit, [ :pointer, :uint32 ], :bool
- attfunc :tctdbopen, [ :pointer, :string, :int ], :int
+ attfunc :tctdbopen, [ :pointer, :string, :int ], :bool
- attfunc :tab_close, :tctdbclose, [ :pointer ], :int
+ attfunc :tab_close, :tctdbclose, [ :pointer ], :bool
attfunc :tab_genuid, :tctdbgenuid, [ :pointer ], :int64
attfunc :tab_get, :tctdbget, [ :pointer, :pointer, :int ], :pointer
- attfunc :tab_iterinit, :tctdbiterinit, [ :pointer ], :int
+ attfunc :tab_iterinit, :tctdbiterinit, [ :pointer ], :bool
attfunc :tab_iternext, :tctdbiternext, [ :pointer, :pointer ], :pointer
- attfunc :tab_put, :tctdbput, [ :pointer, :pointer, :int, :pointer ], :int
+ attfunc :tab_put, :tctdbput, [ :pointer, :pointer, :int, :pointer ], :bool
#attfunc :tctdbput3, [ :pointer, :string, :string ], :int
# not using it anymore, Ruby can turn an array into a hash so easily
- attfunc :tab_out, :tctdbout, [ :pointer, :string, :int ], :int
+ attfunc :tab_out, :tctdbout, [ :pointer, :string, :int ], :bool
attfunc :tab_ecode, :tctdbecode, [ :pointer ], :int
attfunc :tab_errmsg, :tctdberrmsg, [ :int ], :string
@@ -151,13 +151,13 @@ class << self
attfunc :tab_rnum, :tctdbrnum, [ :pointer ], :uint64
- attfunc :tab_vanish, :tctdbvanish, [ :pointer ], :int
+ attfunc :tab_vanish, :tctdbvanish, [ :pointer ], :bool
- attfunc :tab_setindex, :tctdbsetindex, [ :pointer, :string, :int ], :int
+ attfunc :tab_setindex, :tctdbsetindex, [ :pointer, :string, :int ], :bool
- attfunc :tctdbtranbegin, [ :pointer ], :int
- attfunc :tctdbtrancommit, [ :pointer ], :int
- attfunc :tctdbtranabort, [ :pointer ], :int
+ attfunc :tctdbtranbegin, [ :pointer ], :bool
+ attfunc :tctdbtrancommit, [ :pointer ], :bool
+ attfunc :tctdbtranabort, [ :pointer ], :bool
attfunc :tab_fwmkeys, :tctdbfwmkeys, [ :pointer, :pointer, :int, :int ], :pointer
@@ -166,7 +166,7 @@ class << self
#
# tctdbqry functions
#
- # http://tokyocabinet.sourceforge.net/spex-en.html#tctdbapi
+ # http://1978th.net/tokyocabinet/spex-en.html#tctdbapi
attfunc :qry_new, :tctdbqrynew, [ :pointer ], :pointer
attfunc :qry_del, :tctdbqrydel, [ :pointer ], :void
@@ -175,7 +175,7 @@ class << self
attfunc :qry_setorder, :tctdbqrysetorder, [ :pointer, :string, :int ], :void
callback :TDBQRYPROC, [:pointer, :int, :pointer, :pointer], :int
- attfunc :qry_proc, :tctdbqryproc, [ :pointer, :TDBQRYPROC, :pointer], :int
+ attfunc :qry_proc, :tctdbqryproc, [ :pointer, :TDBQRYPROC, :pointer], :bool
begin # since TC 1.4.10
@@ -185,17 +185,17 @@ class << self
end
attfunc :qry_search, :tctdbqrysearch, [ :pointer ], :pointer
- attfunc :qry_searchout, :tctdbqrysearchout, [ :pointer ], :int
+ attfunc :qry_searchout, :tctdbqrysearchout, [ :pointer ], :bool
# since TC 1.4.12
attfunc :qry_count, :tctdbqrycount, [ :pointer ], :int
#
# tcbdb functions
#
- # http://tokyocabinet.sourceforge.net/spex-en.html#tcbdbapi
+ # http://1978th.net/tokyocabinet/spex-en.html#tcbdbapi
- attfunc :tcbdbputdup, [ :pointer, :pointer, :int, :pointer, :int ], :int
+ attfunc :tcbdbputdup, [ :pointer, :pointer, :int, :pointer, :int ], :bool
attfunc :tcbdbget4, [ :pointer, :pointer, :int ], :pointer
#
@@ -212,7 +212,7 @@ class << self
attfunc :tcmapnew, [], :pointer
attfunc :tcmapput, [ :pointer, :pointer, :int, :pointer, :int ], :void
- attfunc :tcmapout, [ :pointer, :pointer, :int ], :int
+ attfunc :tcmapout, [ :pointer, :pointer, :int ], :bool
attfunc :tcmapclear, [ :pointer ], :void
attfunc :tcmapdel, [ :pointer ], :void
attfunc :tcmapget, [ :pointer, :pointer, :int, :pointer ], :pointer
@@ -223,7 +223,7 @@ class << self
#
# tclist functions
#
- # http://tokyocabinet.sourceforge.net/spex-en.html#tcutilapi
+ # http://1978th.net/tokyocabinet/spex-en.html#tcutilapi
attfunc :tclistnew, [], :pointer
attfunc :tclistnum, [ :pointer ], :int
@@ -182,7 +182,7 @@ def close
result = lib.tab_close(@db)
lib.tab_del(@db)
- (result == 1)
+ result
end
# Generates a unique id (in the context of this Table instance)
@@ -230,7 +230,7 @@ def set_index (column_name, *types)
ii = types.inject(0) { |i, t| i = i | INDEX_TYPES[t]; i }
- (lib.tab_setindex(@db, column_name, ii) == 1)
+ lib.tab_setindex(@db, column_name, ii)
end
# Inserts a record in the table db
@@ -255,7 +255,7 @@ def []= (pk, h_or_a)
m.free
- (r == 1) || raise_error # raising potential error after freeing map
+ r || raise_error # raising potential error after freeing map
h_or_a
end
@@ -575,7 +575,7 @@ def get (k)
def libcall (lib_method, *args)
- (lib.send(lib_method, @db, *args) == 1) or raise_error
+ lib.send(lib_method, @db, *args) || raise_error
# stack level too deep with JRuby 1.1.6 :(
#(eval(%{ lib.#{lib_method}(@db, *args) }) == 1) or raise_error
@@ -109,7 +109,7 @@ def delete (k)
v = self[k]
return nil unless v
- (clib.tcmapout(pointer_or_raise, k, Rufus::Tokyo::blen(k)) == 1) ||
+ clib.tcmapout(pointer_or_raise, k, Rufus::Tokyo::blen(k)) ||
raise("failed to remove key '#{k}'")
v
@@ -89,19 +89,16 @@ def initialize( path, mode = "a+", locking = true )
@db = lib.tcidbnew()
- rc = lib.tcidbopen( @db, path, mode_bits | lock_bits )
- raise_error unless rc == 1
+ lib.tcidbopen( @db, path, mode_bits | lock_bits ) || raise_error
end
#
# Close and detach from the database. This instance can not be used anymore
#
def close
- rc = lib.tcidbclose( @db )
- raise_error unless rc == 1
+ lib.tcidbclose( @db ) || raise_error
lib.tcidbdel( @db )
- raise_error unless rc == 1
@db = nil
end
@@ -110,16 +107,14 @@ def close
# Add a new document to the database
#
def store( id, text )
- rc = lib.tcidbput( @db, id, text )
- raise_error unless rc == 1
+ lib.tcidbput( @db, id, text ) || raise_error
end
#
# Remove the given document from the index
#
def delete( id )
- rc = lib.tcidbout( @db, id )
- raise_error unless rc == 1
+ lib.tcidbout( @db, id ) || raise_error
end
#
Oops, something went wrong.

0 comments on commit b70a7dd

Please sign in to comment.