about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2014-02-09 09:52:11 +0000
committerEric Wong <normalperson@yhbt.net>2014-02-09 09:52:11 +0000
commit7c4b13ddc88e25194436fb8b4304a02aee6c610d (patch)
tree09294f97784b57d1b884671481fbce5f79f2c0db
parent2448b18bba6902cffc5f3044081c5945fb1d321d (diff)
downloadruby-tdb-7c4b13ddc88e25194436fb8b4304a02aee6c610d.tar.gz
st.h should probably not be part of the public Ruby API,
and it may well be removed one day (I would support it).
-rw-r--r--ext/tdb/tdb.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/ext/tdb/tdb.c b/ext/tdb/tdb.c
index 58e16bf..c108c38 100644
--- a/ext/tdb/tdb.c
+++ b/ext/tdb/tdb.c
@@ -3,17 +3,12 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
-#ifdef HAVE_RUBY_ST_H
-#  include <ruby/st.h>
-#else
-#  include <st.h>
-#endif
 #include <pthread.h>
 
 /* this protects the global list of tdb objects maintained by libtdb */
 static pthread_mutex_t big_lock = PTHREAD_MUTEX_INITIALIZER;
 static VALUE cTDB, cERR;
-static st_table *exc_hash;
+static VALUE exc_hash;
 static VALUE hashes;
 
 /* must be a macro to prevent GC from killing converted 'val's */
@@ -26,13 +21,14 @@ static VALUE hashes;
 static void init_exc(enum TDB_ERROR ecode, const char *name)
 {
         VALUE exc = rb_define_class_under(cERR, name, cERR);
-        st_insert(exc_hash, (st_data_t)ecode, (st_data_t)exc);
+        rb_hash_aset(exc_hash, INT2NUM(ecode), exc);
 }
 
 static void init_errors(void)
 {
         cERR = rb_define_class_under(cTDB, "ERR", rb_eStandardError);
-        exc_hash = st_init_numtable();
+        exc_hash = rb_hash_new();
+        rb_global_variable(&exc_hash);
 
         init_exc(TDB_ERR_CORRUPT, "CORRUPT");
         init_exc(TDB_ERR_IO, "IO");
@@ -53,7 +49,7 @@ static void my_raise(struct tdb_context *tdb)
 {
         enum TDB_ERROR ecode = tdb_error(tdb);
         const char *str = tdb_errorstr(tdb);
-        VALUE exc;
+        VALUE exc = Qnil;
 
         switch (ecode) {
         case TDB_SUCCESS:
@@ -71,9 +67,10 @@ static void my_raise(struct tdb_context *tdb)
 #ifdef HAVE_CONST_TDB_ERR_NESTING
         case TDB_ERR_NESTING:
 #endif /* HAVE_CONST_TDB_ERR_NESTING */
-                if (!st_lookup(exc_hash, (st_data_t)ecode, (st_data_t *)&exc))
-                        rb_bug("no-existent exception: %s\n", str);
+                exc = rb_hash_aref(exc_hash, INT2NUM(ecode));
         }
+        if (NIL_P(exc))
+                rb_bug("no-existent exception: %s\n", str);
         rb_raise(exc, str);
 }