[前][次][番号順一覧][スレッド一覧]

ruby-changes:27896

From: akr <ko1@a...>
Date: Wed, 27 Mar 2013 00:30:39 +0900 (JST)
Subject: [ruby-changes:27896] akr:r39948 (trunk): * internal.h (TIMET_MAX_PLUS_ONE): Defined.

akr	2013-03-27 00:30:27 +0900 (Wed, 27 Mar 2013)

  New Revision: 39948

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39948

  Log:
    * internal.h (TIMET_MAX_PLUS_ONE): Defined.
    
    * thread.c (double2timeval): Saturate out-of-range values.

  Modified files:
    trunk/ChangeLog
    trunk/internal.h
    trunk/thread.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39947)
+++ ChangeLog	(revision 39948)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Mar 27 00:28:45 2013  Tanaka Akira  <akr@f...>
+
+	* internal.h (TIMET_MAX_PLUS_ONE): Defined.
+
+	* thread.c (double2timeval): Saturate out-of-range values. 
+
 Tue Mar 26 23:41:18 2013  Tanaka Akira  <akr@f...>
 
 	* internal.h: Define TIMET_MAX and TIMET_MIN here.
Index: thread.c
===================================================================
--- thread.c	(revision 39947)
+++ thread.c	(revision 39948)
@@ -916,17 +916,21 @@ double2timeval(double d) https://github.com/ruby/ruby/blob/trunk/thread.c#L916
 {
     struct timeval time;
 
-    if (isinf(d)) {
+    if (TIMET_MAX_PLUS_ONE <= d) {
         time.tv_sec = TIMET_MAX;
+        time.tv_usec = 999999;
+    }
+    else if (d <= TIMET_MIN) {
+        time.tv_sec = TIMET_MIN;
         time.tv_usec = 0;
-        return time;
     }
-
-    time.tv_sec = (int)d;
-    time.tv_usec = (int)((d - (int)d) * 1e6);
-    if (time.tv_usec < 0) {
-	time.tv_usec += (int)1e6;
-	time.tv_sec -= 1;
+    else {
+        time.tv_sec = (time_t)d;
+        time.tv_usec = (int)((d - (time_t)d) * 1e6);
+        if (time.tv_usec < 0) {
+            time.tv_usec += (int)1e6;
+            time.tv_sec -= 1;
+        }
     }
     return time;
 }
Index: internal.h
===================================================================
--- internal.h	(revision 39947)
+++ internal.h	(revision 39948)
@@ -22,6 +22,10 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/internal.h#L22
 #define TIMET_MAX (~(time_t)0 <= 0 ? (time_t)((~(unsigned_time_t)0) >> 1) : (time_t)(~(unsigned_time_t)0))
 #define TIMET_MIN (~(time_t)0 <= 0 ? (time_t)(((unsigned_time_t)1) << (sizeof(time_t) * CHAR_BIT - 1)) : (time_t)0)
 
+#define TIMET_MAX_PLUS_ONE (~(time_t)0 <= 0 ? \
+    ((time_t)1 << (sizeof(time_t) * CHAR_BIT / 2)) * (double)((time_t)1 << (sizeof(time_t) * CHAR_BIT / 2 - 1)) : \
+    ((time_t)1 << (sizeof(time_t) * CHAR_BIT / 2)) * (double)((time_t)1 << (sizeof(time_t) * CHAR_BIT / 2)))
+
 struct rb_deprecated_classext_struct {
     char conflict[sizeof(VALUE) * 3];
 };

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]