summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-02 14:14:12 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-02 14:14:12 -0800
commitcd3d6d573985cac087bd51f44bd8ad87b9e4e429 (patch)
treeb4c3f7b28e4643c9cdfdd75fd036def2bd7dc1ba
parentedb517aee23616ee1842148fb7e9afc7aebc6139 (diff)
We still need a lot of work in this area, but this is better
than nothing.
-rw-r--r--README9
-rw-r--r--ext/tdb/tdb.c65
-rw-r--r--test/test_tdb.rb10
3 files changed, 67 insertions, 17 deletions
diff --git a/README b/README
index bc174f3..b729ac6 100644
--- a/README
+++ b/README
@@ -33,6 +33,15 @@ You may also install it via RubyGems on RubyGems.org:
 
   gem install tdb
 
+If you have a tdb installation in a non-standard prefix, you
+will have to use:
+
+  gem install tdb -- --with-tdb-dir=$PFX
+
+Or if you have a non-standard prefix that linkers normally do not search:
+
+  gem install tdb -- --with-tdb-dir=$PFX --with-dldflags=-Wl,-rpath=$PFX/lib
+
 You can get the latest source via git from the following locations
 (these versions may not be stable):
 
diff --git a/ext/tdb/tdb.c b/ext/tdb/tdb.c
index 0ad7d5f..a68c360 100644
--- a/ext/tdb/tdb.c
+++ b/ext/tdb/tdb.c
@@ -205,6 +205,34 @@ static void set_args(struct open_args *o, VALUE opts)
         }
 }
 
+/*
+ * :call-seq:
+ *
+ *        TDB.new("/path/to/file") -> TDB
+ *        TDB.new("/path/to/file", :hash_size => 666) -> TDB
+ *        TDB.new("/path/to/file", :hash => :murmur2) -> TDB
+ *        TDB.new("/path/to/file", :open_flags => IO::RDONLY) -> TDB
+ *        TDB.new("/path/to/file", :tdb_flags => TDB::NOSYNC) -> TDB
+ *
+ * Initializes a TDB context.  It takes several options.
+ *
+ * :hash_size - the number of buckets, this is the most important tuning
+ * parameter when creating large databases.  This parameter only affects
+ * the creation of new databases.
+ *
+ * :open_flags - a bit mask of IO flags passed directly to open(2),
+ * File.open-compatible flags are accepted.
+ *
+ * :hash - any of the hashes described in Hash_Functions.
+ * This must remain the same for all clients.
+ *
+ * :tdb_flags - a bitmask of any combination of TDB::CLEAR_IF_FIRST,
+ * TDB::INTERNAL, TDB::NOLOCK, TDB::NOMMAP, TDB::CONVERT,
+ * TDB::BIGENDIAN, TDB::NOSYNC, TDB::SEQNUM, TDB::VOLATILE,
+ * TDB::ALLOW_NESTING, TDB::DISALLOW_NESTING, TDB::INCOMPATIBLE_HASH
+ *
+ * :mode - octal mode mask passed to open(2)
+ */
 static VALUE init(int argc, VALUE *argv, VALUE self)
 {
         struct tdb_context *tdb = db(self, 0);
@@ -592,7 +620,12 @@ void Init_tdb_ext(void)
         cTDB = rb_define_class("TDB", rb_cObject);
 
         hashes = rb_hash_new();
-        rb_define_const(cTDB, "HASHES", hashes);
+
+        /*
+         * Available hash functions, the key is the name of the hash
+         * and the value is a pointer for internal for usage.
+         */
+        rb_define_const(cTDB, "HASHES", hashes);
 
         rb_define_alloc_func(cTDB, alloc);
         rb_include_module(cTDB, rb_mEnumerable);
@@ -630,51 +663,49 @@ void Init_tdb_ext(void)
         init_errors();
         init_hashes();
 
-#define tdb_CONST(x) rb_define_const(cTDB, #x, UINT2NUM(TDB_##x))
-
         /* just a readability place holder */
-        tdb_CONST(DEFAULT);
+        rb_define_const(cTDB, "DEFAULT", UINT2NUM(TDB_DEFAULT));
 
         /* clear database if we are the only one with it open */
-        tdb_CONST(CLEAR_IF_FIRST);
+        rb_define_const(cTDB, "CLEAR_IF_FIRST", UINT2NUM(TDB_CLEAR_IF_FIRST));
 
         /* don't store on disk, use in-memory database */
-        tdb_CONST(INTERNAL);
+        rb_define_const(cTDB, "INTERNAL", UINT2NUM(TDB_INTERNAL));
 
         /* don't do any locking */
-        tdb_CONST(NOLOCK);
+        rb_define_const(cTDB, "NOLOCK", UINT2NUM(TDB_NOLOCK));
 
         /* don't use mmap */
-        tdb_CONST(NOMMAP);
+        rb_define_const(cTDB, "NOMMAP", UINT2NUM(TDB_NOMMAP));
 
         /* convert endian (internal use) */
-        tdb_CONST(CONVERT);
+        rb_define_const(cTDB, "CONVERT", UINT2NUM(TDB_CONVERT));
 
         /* header is big-endian (internal use) */
-        tdb_CONST(BIGENDIAN);
+        rb_define_const(cTDB, "BIGENDIAN", UINT2NUM(TDB_BIGENDIAN));
 
         /* don't use synchronous transactions */
-        tdb_CONST(NOSYNC);
+        rb_define_const(cTDB, "NOSYNC", UINT2NUM(TDB_NOSYNC));
 
         /* maintain a sequence number */
-        tdb_CONST(SEQNUM);
+        rb_define_const(cTDB, "SEQNUM", UINT2NUM(TDB_SEQNUM));
 
         /* Activate the per-hashchain freelist, default 5 */
-        tdb_CONST(VOLATILE);
+        rb_define_const(cTDB, "VOLATILE", UINT2NUM(TDB_VOLATILE));
 
 #ifdef TDB_ALLOW_NESTING
         /* Allow transactions to nest */
-        tdb_CONST(ALLOW_NESTING);
+        rb_define_const(cTDB, "ALLOW_NESTING", UINT2NUM(TDB_ALLOW_NESTING));
 #endif
 
 #ifdef TDB_DISALLOW_NESTING
         /* Disallow transactions to nest */
-        tdb_CONST(DISALLOW_NESTING);
+        rb_define_const(cTDB, "DISALLOW_NESTING", UINT2NUM(TDB_DISALLOW_NESTING));
 #endif
 
 #ifdef TDB_INCOMPATIBLE_HASH
-        /* Better hashing: can't be opened by tdb < 1.2.6. */
-        tdb_CONST(INCOMPATIBLE_HASH);
+        /* Better hashing, but can't be opened by tdb < 1.2.6. */
+        rb_define_const(cTDB, "INCOMPATIBLE_HASH", UINT2NUM(TDB_INCOMPATIBLE_HASH));
 #endif
 }
 
diff --git a/test/test_tdb.rb b/test/test_tdb.rb
index 188e219..bd25203 100644
--- a/test/test_tdb.rb
+++ b/test/test_tdb.rb
@@ -257,4 +257,14 @@ class TestTdb < Test::Unit::TestCase
     assert Process.waitpid2(pid)[1].success?
     assert_equal true, @tdb.trylockall
   end
+
+  def test_check_constant_typos
+    names = {}
+    TDB.constants.each { |const| names[const] = TDB.const_get(const) }
+    assert_equal TDB.constants.size, names.size
+
+    values = {}
+    TDB.constants.each { |const| values[TDB.const_get(const)] = const }
+    assert_equal TDB.constants.size, values.size
+  end
 end