diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-08-27 08:31:08 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-08-27 08:31:08 +0000 |
commit | c45908e41f47c88674b73a754ecd0535449b667a (patch) | |
tree | a27bb0f2ca80fa80b9582ddcb8312eee673b0bd5 /time.c | |
parent | cd3d4a01f248fad1a73ff0b66b7a8d1653f64c19 (diff) | |
download | ruby-c45908e41f47c88674b73a754ecd0535449b667a.tar.gz |
* file.c (rb_find_file): $LOAD_PATH must not be empty.
* file.c (rb_find_file_ext): ditto.
* range.c (range_eq): class check should be based on range.class,
instead of Range to work with Range.dup.
* range.c (range_eql): ditto.
* class.c (rb_mod_dup): need to preserve metaclass and flags.
* object.c (rb_cstr_to_dbl): had a buffer overrun.
* marshal.c (w_class): integrate singleton check into a funciton
to follow DRY principle.
* marshal.c (w_uclass): should check singleton method.
* object.c (rb_obj_dup): dmark and dfree functions must be match
for T_DATA type.
* object.c (rb_obj_dup): class of the duped object must be match
to the class of the original.
* re.c (rb_reg_quote): do not escape \t, \f, \r, \n, for they are
not regular expression metacharacters.
* time.c (time_s_alloc): use time_free instead of free (null check,
also serves for type mark).
* time.c (time_s_at): check dfree function too.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 67 |
1 files changed, 34 insertions, 33 deletions
@@ -43,6 +43,13 @@ struct time_object { #define GetTimeval(obj, tobj) \ Data_Get_Struct(obj, struct time_object, tobj) +static void +time_free(tobj) + struct time_object *tobj; +{ + if (tobj) free(tobj); +} + static VALUE time_s_alloc(klass) VALUE klass; @@ -50,7 +57,7 @@ time_s_alloc(klass) VALUE obj; struct time_object *tobj; - obj = Data_Make_Struct(klass, struct time_object, 0, free, tobj); + obj = Data_Make_Struct(klass, struct time_object, 0, time_free, tobj); tobj->tm_got=0; if (gettimeofday(&tobj->tv, 0) < 0) { rb_sys_fail("gettimeofday"); @@ -100,7 +107,7 @@ time_new_internal(klass, sec, usec) rb_raise(rb_eArgError, "time must be positive"); #endif - obj = Data_Make_Struct(klass, struct time_object, 0, free, tobj); + obj = Data_Make_Struct(klass, struct time_object, 0, time_free, tobj); tobj->tm_got = 0; tobj->tv.tv_sec = sec; tobj->tv.tv_usec = usec; @@ -179,7 +186,7 @@ rb_time_timeval(time) struct time_object *tobj; struct timeval t; - if (rb_obj_is_kind_of(time, rb_cTime)) { + if (TYPE(time) == T_DATA && RDATA(time)->dfree == time_free) { GetTimeval(time, tobj); t = tobj->tv; return t; @@ -204,7 +211,7 @@ time_s_at(argc, argv, klass) tv = rb_time_timeval(time); } t = time_new_internal(klass, tv.tv_sec, tv.tv_usec); - if (TYPE(time) == T_DATA) { + if (TYPE(time) == T_DATA && RDATA(time)->dfree == time_free) { struct time_object *tobj, *tobj2; GetTimeval(time, tobj); @@ -717,7 +724,7 @@ time_cmp(time1, time2) RFLOAT(time2)->value); } - if (rb_obj_is_kind_of(time2, rb_cTime)) { + if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) { GetTimeval(time2, tobj2); if (tobj1->tv.tv_sec == tobj2->tv.tv_sec) { if (tobj1->tv.tv_usec == tobj2->tv.tv_usec) return INT2FIX(0); @@ -754,7 +761,7 @@ time_eql(time1, time2) struct time_object *tobj1, *tobj2; GetTimeval(time1, tobj1); - if (rb_obj_is_kind_of(time2, rb_cTime)) { + if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) { GetTimeval(time2, tobj2); if (tobj1->tv.tv_sec == tobj2->tv.tv_sec) { if (tobj1->tv.tv_usec == tobj2->tv.tv_usec) return Qtrue; @@ -787,18 +794,28 @@ time_hash(time) } static VALUE -time_clone(time) - VALUE time; +time_become(copy, time) + VALUE copy, time; { - VALUE clone; - struct time_object *tobj, *tclone; + struct time_object *tobj, *tcopy; + if (TYPE(time) != T_DATA || RDATA(time)->dfree != time_free) { + rb_raise(rb_eTypeError, "wrong argument type"); + } GetTimeval(time, tobj); - clone = Data_Make_Struct(0, struct time_object, 0, free, tclone); - CLONESETUP(clone, time); - MEMCPY(tclone, tobj, struct time_object, 1); + GetTimeval(copy, tcopy); + MEMCPY(tcopy, tobj, struct time_object, 1); + + return copy; +} - return clone; +static VALUE +time_dup(time) + VALUE time; +{ + VALUE dup = time_s_alloc(rb_cTime); + time_become(dup, time); + return dup; } static void @@ -863,21 +880,6 @@ time_gmtime(time) } static VALUE -time_dup(time) - VALUE time; -{ - VALUE clone; - struct time_object *tobj, *tclone; - - GetTimeval(time, tobj); - clone = Data_Make_Struct(0, struct time_object, 0, free, tclone); - DUPSETUP(clone, time); - MEMCPY(tclone, tobj, struct time_object, 1); - - return clone; -} - -static VALUE time_getlocaltime(time) VALUE time; { @@ -948,7 +950,7 @@ time_plus(time1, time2) GetTimeval(time1, tobj); - if (rb_obj_is_kind_of(time2, rb_cTime)) { + if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) { rb_raise(rb_eTypeError, "time + time?"); } v = NUM2DBL(time2); @@ -988,7 +990,7 @@ time_minus(time1, time2) double f, d, v; GetTimeval(time1, tobj); - if (rb_obj_is_kind_of(time2, rb_cTime)) { + if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) { struct time_object *tobj2; GetTimeval(time2, tobj2); @@ -1429,8 +1431,7 @@ Init_Time() rb_define_method(rb_cTime, "<=>", time_cmp, 1); rb_define_method(rb_cTime, "eql?", time_eql, 1); rb_define_method(rb_cTime, "hash", time_hash, 0); - rb_define_method(rb_cTime, "clone", time_clone, 0); - rb_define_method(rb_cTime, "dup", time_dup, 0); + rb_define_method(rb_cTime, "become", time_become, 1); rb_define_method(rb_cTime, "localtime", time_localtime, 0); rb_define_method(rb_cTime, "gmtime", time_gmtime, 0); |