Skip to content

Commit

Permalink
define allocation method for Time class; close #1474
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Aug 14, 2013
1 parent 0dfda0c commit b7d6b4d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions mrbgems/mruby-time/src/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ mrb_time_wrap(mrb_state *mrb, struct RClass *tc, struct mrb_time *tm)

/* Allocates a mrb_time object and initializes it. */
static struct mrb_time*
mrb_time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone)
time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone)
{
struct mrb_time *tm;

Expand All @@ -171,7 +171,14 @@ mrb_time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezo
static mrb_value
mrb_time_make(mrb_state *mrb, struct RClass *c, double sec, double usec, enum mrb_timezone timezone)
{
return mrb_time_wrap(mrb, c, mrb_time_alloc(mrb, sec, usec, timezone));
return mrb_time_wrap(mrb, c, time_alloc(mrb, sec, usec, timezone));
}

/* Allocates a mrb_time object and initializes it. */
static mrb_value
mrb_time_alloc(mrb_state *mrb, mrb_value cv)
{
return mrb_time_make(mrb, mrb_class_ptr(cv), 0, 0, MRB_TIMEZONE_NONE);
}

static struct mrb_time*
Expand Down Expand Up @@ -253,7 +260,7 @@ time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday,
mrb_raise(mrb, E_ARGUMENT_ERROR, "Not a valid time.");
}

return mrb_time_alloc(mrb, nowsecs, ausec, timezone);
return time_alloc(mrb, nowsecs, ausec, timezone);
}

/* 15.2.19.6.2 */
Expand Down Expand Up @@ -685,6 +692,7 @@ mrb_mruby_time_gem_init(mrb_state* mrb)
tc = mrb_define_class(mrb, "Time", mrb->object_class);
MRB_SET_INSTANCE_TT(tc, MRB_TT_DATA);
mrb_include_module(mrb, tc, mrb_class_get(mrb, "Comparable"));
mrb_define_class_method(mrb, tc, "alloc", mrb_time_alloc, MRB_ARGS_NONE());
mrb_define_class_method(mrb, tc, "at", mrb_time_at, MRB_ARGS_ANY()); /* 15.2.19.6.1 */
mrb_define_class_method(mrb, tc, "gm", mrb_time_gm, MRB_ARGS_ARG(1,6)); /* 15.2.19.6.2 */
mrb_define_class_method(mrb, tc, "local", mrb_time_local, MRB_ARGS_ARG(1,6)); /* 15.2.19.6.3 */
Expand Down

0 comments on commit b7d6b4d

Please sign in to comment.