ext/bdb1/delegate.c in bdb1-0.2.4 vs ext/bdb1/delegate.c in bdb1-0.2.5
- old
+ new
@@ -2,19 +2,17 @@
static ID id_send;
VALUE bdb1_cDelegate;
void
-bdb1_deleg_free(delegst)
- struct deleg_class *delegst;
+bdb1_deleg_free(struct deleg_class *delegst)
{
free(delegst);
}
void
-bdb1_deleg_mark(delegst)
- struct deleg_class *delegst;
+bdb1_deleg_mark(struct deleg_class *delegst)
{
bdb1_DB *dbst;
if (delegst->db) {
Data_Get_Struct(delegst->db, bdb1_DB, dbst);
@@ -24,50 +22,20 @@
}
}
if (delegst->obj) rb_gc_mark(delegst->obj);
}
-#ifndef HAVE_RB_BLOCK_CALL
-
static VALUE
-bdb1_deleg_each(tmp)
- VALUE *tmp;
+bdb1_deleg_missing(int argc, VALUE *argv, VALUE obj)
{
- return rb_funcall2(tmp[0], id_send, (int)tmp[1], (VALUE *)tmp[2]);
-}
-
-static VALUE
-bdb1_deleg_yield(i, res)
- VALUE i, res;
-{
- return rb_ary_push(res, rb_yield(i));
-}
-
-#endif
-
-static VALUE
-bdb1_deleg_missing(argc, argv, obj)
- int argc;
- VALUE *argv, obj;
-{
struct deleg_class *delegst, *newst;
bdb1_DB *dbst;
VALUE res, new;
Data_Get_Struct(obj, struct deleg_class, delegst);
if (rb_block_given_p()) {
-#if HAVE_RB_BLOCK_CALL
res = rb_block_call(delegst->obj, id_send, argc, argv, rb_yield, 0);
-#else
- VALUE tmp[3];
-
- tmp[0] = delegst->obj;
- tmp[1] = (VALUE)argc;
- tmp[2] = (VALUE)argv;
- res = rb_ary_new();
- rb_iterate(bdb1_deleg_each, (VALUE)tmp, bdb1_deleg_yield, res);
-#endif
}
else {
res = rb_funcall2(delegst->obj, id_send, argc, argv);
}
Data_Get_Struct(delegst->db, bdb1_DB, dbst);
@@ -97,84 +65,96 @@
bdb1_put(2, nargv, delegst->db);
}
return res;
}
-#define DELEG_0(id) \
- VALUE obj; \
+#define DELEG_0(meth) \
{ \
struct deleg_class *delegst; \
Data_Get_Struct(obj, struct deleg_class, delegst); \
- return rb_funcall2(delegst->obj, id, 0, 0); \
+ return rb_funcall2(delegst->obj, rb_intern(meth), 0, 0); \
}
-static VALUE bdb1_deleg_inspect(obj) DELEG_0(rb_intern("inspect"))
-static VALUE bdb1_deleg_to_s(obj) DELEG_0(rb_intern("to_s"))
-static VALUE bdb1_deleg_to_str(obj) DELEG_0(rb_intern("to_str"))
-static VALUE bdb1_deleg_to_a(obj) DELEG_0(rb_intern("to_a"))
-static VALUE bdb1_deleg_to_ary(obj) DELEG_0(rb_intern("to_ary"))
-static VALUE bdb1_deleg_to_i(obj) DELEG_0(rb_intern("to_i"))
-static VALUE bdb1_deleg_to_int(obj) DELEG_0(rb_intern("to_int"))
-static VALUE bdb1_deleg_to_f(obj) DELEG_0(rb_intern("to_f"))
-static VALUE bdb1_deleg_to_hash(obj) DELEG_0(rb_intern("to_hash"))
-static VALUE bdb1_deleg_to_io(obj) DELEG_0(rb_intern("to_io"))
-static VALUE bdb1_deleg_to_proc(obj) DELEG_0(rb_intern("to_proc"))
+static VALUE bdb1_deleg_inspect(VALUE obj) DELEG_0("inspect")
+static VALUE bdb1_deleg_to_s(VALUE obj) DELEG_0("to_s")
+static VALUE bdb1_deleg_to_str(VALUE obj) DELEG_0("to_str")
+static VALUE bdb1_deleg_to_a(VALUE obj) DELEG_0("to_a")
+static VALUE bdb1_deleg_to_ary(VALUE obj) DELEG_0("to_ary")
+static VALUE bdb1_deleg_to_i(VALUE obj) DELEG_0("to_i")
+static VALUE bdb1_deleg_to_int(VALUE obj) DELEG_0("to_int")
+static VALUE bdb1_deleg_to_f(VALUE obj) DELEG_0("to_f")
+static VALUE bdb1_deleg_to_hash(VALUE obj) DELEG_0("to_hash")
+static VALUE bdb1_deleg_to_io(VALUE obj) DELEG_0("to_io")
+static VALUE bdb1_deleg_to_proc(VALUE obj) DELEG_0("to_proc")
VALUE
-bdb1_deleg_to_orig(obj)
- VALUE obj;
+bdb1_deleg_to_orig(VALUE obj)
{
struct deleg_class *delegst;
Data_Get_Struct(obj, struct deleg_class, delegst);
return delegst->obj;
}
static VALUE
-bdb1_deleg_orig(obj)
- VALUE obj;
+bdb1_deleg_orig(VALUE obj)
{
return obj;
}
static VALUE
-bdb1_deleg_dump(obj, limit)
- VALUE obj, limit;
+bdb1_deleg_dump(VALUE obj, VALUE limit)
{
struct deleg_class *delegst;
bdb1_DB *dbst;
Data_Get_Struct(obj, struct deleg_class, delegst);
Data_Get_Struct(delegst->db, bdb1_DB, dbst);
return rb_funcall(dbst->marshal, rb_intern("dump"), 1, delegst->obj);
}
static VALUE
-bdb1_deleg_load(obj, str)
- VALUE obj, str;
+bdb1_deleg_load(VALUE obj, VALUE str)
{
bdb1_DB *dbst;
- if ((obj = rb_thread_local_aref(rb_thread_current(), bdb1_id_current_db)) == Qnil) {
+ if (NIL_P(obj = rb_thread_local_aref(rb_thread_current(), bdb1_id_current_db))) {
rb_raise(bdb1_eFatal, "BUG : current_db not set");
}
Data_Get_Struct(obj, bdb1_DB, dbst);
return rb_funcall(dbst->marshal, rb_intern("load"), 1, str);
}
-void bdb1_init_delegator()
+void
+bdb1_init_delegator(void)
{
id_send = rb_intern("send");
bdb1_cDelegate = rb_define_class_under(bdb1_mDb, "Delegate", rb_cObject);
{
VALUE ary, tmp = Qfalse;
- char *method;
int i;
+ ID id_eq = rb_intern("=="),
+ id_eqq = rb_intern("==="),
+ id_match = rb_intern("=~"),
+ id_not = rb_intern("!"),
+ id_neq = rb_intern("!="),
+ id_notmatch = rb_intern("!~");
ary = rb_class_instance_methods(1, &tmp, rb_mKernel);
for (i = 0; i < RARRAY_LEN(ary); i++) {
- method = StringValuePtr(RARRAY_PTR(ary)[i]);
- if (!strcmp(method, "==") ||
- !strcmp(method, "===") || !strcmp(method, "=~")) continue;
- rb_undef_method(bdb1_cDelegate, method);
+ VALUE method = RARRAY_PTR(ary)[i];
+ VALUE mid;
+ if (!SYMBOL_P(method)) {
+ Check_Type(method, T_STRING);
+ mid = rb_intern(RSTRING_PTR(method));
+ }
+ else
+ mid = SYM2ID(method);
+ if (mid == id_eq ||
+ mid == id_eqq ||
+ mid == id_match ||
+ mid == id_not ||
+ mid == id_neq ||
+ mid == id_notmatch) continue;
+ rb_undef_method(bdb1_cDelegate, rb_id2name(mid));
}
}
rb_define_method(bdb1_cDelegate, "method_missing", bdb1_deleg_missing, -1);
rb_define_method(bdb1_cDelegate, "inspect", bdb1_deleg_inspect, 0);
rb_define_method(bdb1_cDelegate, "to_s", bdb1_deleg_to_s, 0);