diff --git a/ChangeLog b/ChangeLog index 9ac34fbf815bc5..a1e4eeffb2f636 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,17 @@ Mon Dec 3 16:06:04 2001 Usaku Nakamura * configure.in: not use X11BASE, since it's not always set. +Mon Dec 3 09:59:08 2001 Yukihiro Matsumoto + + * time.c (time_new_internal): round usec overflow and underflow + here. + + * time.c (time_plus): remove overflow/underflow check. + + * time.c (time_minus): ditto. + + * time.c (time_cmp): should consider tv_usec too. + Mon Dec 3 03:29:17 2001 Usaku Nakamura * configure.in: apply patch from NetBSD's pkgsrc (patch-aa). @@ -21,12 +32,22 @@ Sat Dec 1 23:23:57 2001 Akinori MUSHA * ext/Setup*, ext/syslog/*: import the "syslog" module from the rough ruby project. +Sat Dec 1 12:13:20 2001 Yukihiro Matsumoto + + * time.c (time_gmtime): time_modify() should be called even if tm + struct is not calculated yet. + Fri Nov 30 00:30:00 2001 Usaku Nakamura * README.EXT: Appendix B is duplicated. * README.EXT.ja: ditto. +Thu Nov 29 00:28:07 2001 Yukihiro Matsumoto + + * string.c (rb_str_equal): object with to_str must be treated as a + string. + Wed Nov 28 18:46:28 2001 Ville Mattila * eval.c (rb_thread_select): should subtract timeofday() from diff --git a/eval.c b/eval.c index 487d5c472b0ac1..e0d4e9b7721414 100644 --- a/eval.c +++ b/eval.c @@ -7598,7 +7598,7 @@ rb_thread_schedule() if (select_timeout && n == 0) { if (now < 0.0) now = timeofday(); FOREACH_THREAD_FROM(curr, th) { - if ((th->wait_for & (WAIT_SELECT|WAIT_TIME)) && th->delay < now) { + if ((th->wait_for & (WAIT_SELECT|WAIT_TIME)) && th->delay <= now) { th->status = THREAD_RUNNABLE; th->wait_for = 0; th->select_value = 0; diff --git a/string.c b/string.c index ab7519be8d94ea..01540828683887 100644 --- a/string.c +++ b/string.c @@ -563,13 +563,28 @@ rb_str_cmp(str1, str2) return -1; } +to_str(str) + VALUE str; +{ + return rb_funcall(str, rb_intern("to_str"), 0); +} + +static VALUE +str_or_nil(str) + VALUE str; +{ + return rb_rescue(to_str, (VALUE)str, 0, 0); +} + static VALUE rb_str_equal(str1, str2) VALUE str1, str2; { if (str1 == str2) return Qtrue; - if (TYPE(str2) != T_STRING) - return Qfalse; + if (TYPE(str2) != T_STRING) { + str2 = str_or_nil(str2); + if (NIL_P(str2)) return Qfalse; + } if (RSTRING(str1)->len == RSTRING(str2)->len && rb_str_cmp(str1, str2) == 0) { diff --git a/time.c b/time.c index df22b1e7b1272d..5464499ecacdb0 100644 --- a/time.c +++ b/time.c @@ -87,6 +87,14 @@ time_new_internal(klass, sec, usec) VALUE obj; struct time_object *tobj; + if (usec >= 1000000) { /* usec overflow */ + sec += usec / 1000000; + usec %= 1000000; + } + if (usec < 0) { /* usec underflow */ + sec -= (-usec) / 1000000; + usec %= 1000000; + } if (sec < 0 || (sec == 0 && usec < 0)) rb_raise(rb_eArgError, "time must be positive"); @@ -459,7 +467,13 @@ time_cmp(time1, time2) switch (TYPE(time2)) { case T_FIXNUM: i = FIX2LONG(time2); - if (tobj1->tv.tv_sec == i) return INT2FIX(0); + if (tobj1->tv.tv_sec == i) { + if (tobj1->tv.tv_usec == 0) + return INT2FIX(0); + if (tobj1->tv.tv_usec > 0) + return INT2FIX(1); + return INT2FIX(-1); + } if (tobj1->tv.tv_sec > i) return INT2FIX(1); return INT2FIX(-1); @@ -564,8 +578,11 @@ time_localtime(time) time_t t; GetTimeval(time, tobj); - if (tobj->tm_got) { - if (!tobj->gmt) return time; + if (!tobj->gmt) { + if (tobj->tm_got) + return time; + } + else { time_modify(time); } t = tobj->tv.tv_sec; @@ -585,8 +602,11 @@ time_gmtime(time) time_t t; GetTimeval(time, tobj); - if (tobj->tm_got) { - if (tobj->gmt) return time; + if (tobj->gmt) { + if (tobj->tm_got) + return time; + } + else { time_modify(time); } t = tobj->tv.tv_sec; @@ -662,14 +682,6 @@ time_plus(time1, time2) usec = tobj->tv.tv_usec + (time_t)((f - (double)sec)*1e6); sec = tobj->tv.tv_sec + sec; - if (usec >= 1000000) { /* usec overflow */ - sec++; - usec -= 1000000; - } - if (usec < 0) { /* usec underflow */ - sec--; - usec += 1000000; - } time2 = rb_time_new(sec, usec); if (tobj->gmt) { GetTimeval(time2, tobj); @@ -703,14 +715,6 @@ time_minus(time1, time2) sec = tobj->tv.tv_sec - sec; } - if (usec >= 1000000) { /* usec overflow */ - sec++; - usec -= 1000000; - } - if (usec < 0) { /* usec underflow */ - sec--; - usec += 1000000; - } time2 = rb_time_new(sec, usec); if (tobj->gmt) { GetTimeval(time2, tobj);