From 6f6e18ef825fbae10410c4c84460773e745ae056 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 2 Aug 2012 22:17:27 +0900 Subject: struct.c refactoring --- src/struct.c | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/struct.c b/src/struct.c index a133dc046..beb7c2f46 100644 --- a/src/struct.c +++ b/src/struct.c @@ -367,7 +367,7 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass) name = mrb_nil_value(); rest = mrb_nil_value(); - mrb_get_args(mrb, "&*", &b, &argv, &argc); + mrb_get_args(mrb, "*&", &argv, &argc, &b); if (argc > 0) name = argv[0]; if (argc > 1) rest = argv[1]; if (mrb_type(rest) == MRB_TT_ARRAY) { @@ -400,7 +400,7 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass) return st; } -static long +static int num_members(mrb_state *mrb, struct RClass *klass) { mrb_value members; @@ -418,7 +418,7 @@ static mrb_value mrb_struct_initialize_withArg(mrb_state *mrb, int argc, mrb_value *argv, mrb_value self) { struct RClass *klass = mrb_obj_class(mrb, self); - long n; + int n; struct RStruct *st; mrb_struct_modify(self); @@ -447,34 +447,7 @@ mrb_struct_initialize_m(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value mrb_value mrb_struct_initialize(mrb_state *mrb, mrb_value self, mrb_value values) { - return mrb_struct_initialize_withArg(mrb, RARRAY_LEN/*INT*/(values), RARRAY_PTR(values), self); -} - -mrb_value -mrb_struct_alloc(mrb_state *mrb, mrb_value klass, mrb_value values) -{ - return mrb_class_new_instance(mrb, RARRAY_LEN(values), RARRAY_PTR(values), mrb_class(mrb, klass)); -} - -mrb_value -mrb_struct_new(mrb_state *mrb, struct RClass *klass, ...) -{ - mrb_value tmpargs[N_REF_FUNC], *mem = tmpargs; - int size, i; - va_list args; - - size = mrb_long2int(num_members(mrb, klass)); - if (size > numberof(tmpargs)) { - tmpargs[0] = mrb_ary_new_capa(mrb, size); - mem = RARRAY_PTR(tmpargs[0]); - } - va_start(args, klass); - for (i=0; i