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

ruby-changes:28277

From: nobu <ko1@a...>
Date: Wed, 17 Apr 2013 10:58:38 +0900 (JST)
Subject: [ruby-changes:28277] nobu:r40329 (trunk): thread.c: fix overflow on Windows

nobu	2013-04-17 10:58:25 +0900 (Wed, 17 Apr 2013)

  New Revision: 40329

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

  Log:
    thread.c: fix overflow on Windows
    
    * thread.c (sleep_timeval): get rid of overflow on Windows where
      timeval.tv_sec is not time_t but mere long.

  Modified files:
    trunk/ChangeLog
    trunk/thread.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40328)
+++ ChangeLog	(revision 40329)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Apr 17 10:58:18 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* thread.c (sleep_timeval): get rid of overflow on Windows where
+	  timeval.tv_sec is not time_t but mere long.
+
 Tue Apr 16 23:07:12 2013  Tanaka Akira  <akr@f...>
 
 	* ext/socket/unixsocket.c (unix_send_io): Suppress a warning by clang.
Index: thread.c
===================================================================
--- thread.c	(revision 40328)
+++ thread.c	(revision 40329)
@@ -912,18 +912,19 @@ thread_value(VALUE self) https://github.com/ruby/ruby/blob/trunk/thread.c#L912
  * Thread Scheduling
  */
 
+#if SIGNEDNESS_OF_TIME_T < 0	/* signed */
+# define TIMEVAL_SEC_MAX_P1 (((unsigned_time_t)1) << (sizeof(TYPEOF_TIMEVAL_TV_SEC) * CHAR_BIT - 1))
+# define TIMEVAL_SEC_MAX ((TYPEOF_TIMEVAL_TV_SEC)(TIMEVAL_SEC_MAX_P1 - 1))
+# define TIMEVAL_SEC_MIN ((TYPEOF_TIMEVAL_TV_SEC)TIMEVAL_SEC_MAX_P1)
+#elif SIGNEDNESS_OF_TIME_T > 0	/* unsigned */
+# define TIMEVAL_SEC_MAX ((TYPEOF_TIMEVAL_TV_SEC)(~(unsigned_time_t)0))
+# define TIMEVAL_SEC_MIN ((TYPEOF_TIMEVAL_TV_SEC)0)
+#endif
+
 static struct timeval
 double2timeval(double d)
 {
     /* assume timeval.tv_sec has same signedness as time_t */
-#if SIGNEDNESS_OF_TIME_T < 0	/* signed */
-    const unsigned_time_t TIMEVAL_SEC_MAX_P1 = (((unsigned_time_t)1) << (sizeof(TYPEOF_TIMEVAL_TV_SEC) * CHAR_BIT - 1));
-    const TYPEOF_TIMEVAL_TV_SEC TIMEVAL_SEC_MAX = (TYPEOF_TIMEVAL_TV_SEC)(TIMEVAL_SEC_MAX_P1 - 1);
-    const TYPEOF_TIMEVAL_TV_SEC TIMEVAL_SEC_MIN = (TYPEOF_TIMEVAL_TV_SEC)TIMEVAL_SEC_MAX_P1;
-#elif SIGNEDNESS_OF_TIME_T > 0	/* unsigned */
-    const TYPEOF_TIMEVAL_TV_SEC TIMEVAL_SEC_MAX = (TYPEOF_TIMEVAL_TV_SEC)(~(unsigned_time_t)0);
-    const TYPEOF_TIMEVAL_TV_SEC TIMEVAL_SEC_MIN = (TYPEOF_TIMEVAL_TV_SEC)0;
-#endif
     const double TIMEVAL_SEC_MAX_PLUS_ONE = (2*(double)(TIMEVAL_SEC_MAX/2+1));
 
     struct timeval time;
@@ -994,12 +995,12 @@ sleep_timeval(rb_thread_t *th, struct ti https://github.com/ruby/ruby/blob/trunk/thread.c#L995
     enum rb_thread_status prev_status = th->status;
 
     getclockofday(&to);
-    if (TIMET_MAX - tv.tv_sec < to.tv_sec)
-        to.tv_sec = TIMET_MAX;
+    if (TIMEVAL_SEC_MAX - tv.tv_sec < to.tv_sec)
+        to.tv_sec = TIMEVAL_SEC_MAX;
     else
         to.tv_sec += tv.tv_sec;
     if ((to.tv_usec += tv.tv_usec) >= 1000000) {
-        if (to.tv_sec == TIMET_MAX)
+        if (to.tv_sec == TIMEVAL_SEC_MAX)
             to.tv_usec = 999999;
         else {
             to.tv_sec++;

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

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