Skip to content

Commit

Permalink
* time.c (time_new_internal): round usec overflow and underflow
Browse files Browse the repository at this point in the history
  here.

* time.c (time_plus): remove overflow/underflow check.

* time.c (time_minus): ditto.

* time.c (time_cmp): should consider tv_usec too.

* time.c (time_gmtime): time_modify() should be called even if tm
  struct is not calculated yet.

* string.c (rb_str_equal): object with to_str must be treated as a
  string.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Dec 3, 2001
1 parent 7ff058e commit 5536343
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 24 deletions.
21 changes: 21 additions & 0 deletions ChangeLog
Expand Up @@ -6,6 +6,17 @@ Mon Dec 3 16:06:04 2001 Usaku Nakamura <usa@ruby-lang.org>

* configure.in: not use X11BASE, since it's not always set.

Mon Dec 3 09:59:08 2001 Yukihiro Matsumoto <matz@ruby-lang.org>

* 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 <usa@ruby-lang.org>

* configure.in: apply patch from NetBSD's pkgsrc (patch-aa).
Expand All @@ -21,12 +32,22 @@ Sat Dec 1 23:23:57 2001 Akinori MUSHA <knu@iDaemons.org>
* ext/Setup*, ext/syslog/*: import the "syslog" module from the
rough ruby project.

Sat Dec 1 12:13:20 2001 Yukihiro Matsumoto <matz@ruby-lang.org>

* 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 <usa@ruby-lang.org>

* README.EXT: Appendix B is duplicated.

* README.EXT.ja: ditto.

Thu Nov 29 00:28:07 2001 Yukihiro Matsumoto <matz@ruby-lang.org>

* string.c (rb_str_equal): object with to_str must be treated as a
string.

Wed Nov 28 18:46:28 2001 Ville Mattila <mulperi@iki.fi>

* eval.c (rb_thread_select): should subtract timeofday() from
Expand Down
2 changes: 1 addition & 1 deletion eval.c
Expand Up @@ -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;
Expand Down
19 changes: 17 additions & 2 deletions string.c
Expand Up @@ -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) {
Expand Down
46 changes: 25 additions & 21 deletions time.c
Expand Up @@ -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");

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5536343

Please sign in to comment.