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

ruby-changes:27887

From: akr <ko1@a...>
Date: Tue, 26 Mar 2013 22:16:42 +0900 (JST)
Subject: [ruby-changes:27887] akr:r39939 (trunk): * thread.c (double2timeval): convert the infinity to TIME_MAX to avoid

akr	2013-03-26 22:16:31 +0900 (Tue, 26 Mar 2013)

  New Revision: 39939

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

  Log:
    * thread.c (double2timeval): convert the infinity to TIME_MAX to avoid
      SEGV by Thread.new {}.join(Float::INFINITY) on
      Debian GNU/Linux (amd64).

  Modified files:
    trunk/ChangeLog
    trunk/thread.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39938)
+++ ChangeLog	(revision 39939)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Mar 26 22:14:46 2013  Tanaka Akira  <akr@f...>
+
+	* thread.c (double2timeval): convert the infinity to TIME_MAX to avoid
+	  SEGV by Thread.new {}.join(Float::INFINITY) on
+	  Debian GNU/Linux (amd64).
+
 Mon Mar 25 07:09:20 2013  Eric Hodel  <drbrain@s...>
 
 	* lib/rinda/tuplespace.rb:  Only return tuple entry once on move,
Index: thread.c
===================================================================
--- thread.c	(revision 39938)
+++ thread.c	(revision 39939)
@@ -73,6 +73,9 @@ https://github.com/ruby/ruby/blob/trunk/thread.c#L73
 #define THREAD_DEBUG 0
 #endif
 
+#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)
+
 VALUE rb_cMutex;
 VALUE rb_cThreadShield;
 
@@ -916,6 +919,12 @@ double2timeval(double d) https://github.com/ruby/ruby/blob/trunk/thread.c#L919
 {
     struct timeval time;
 
+    if (isinf(d)) {
+        time.tv_sec = TIMET_MAX;
+        time.tv_usec = 0;
+        return time;
+    }
+
     time.tv_sec = (int)d;
     time.tv_usec = (int)((d - (int)d) * 1e6);
     if (time.tv_usec < 0) {
@@ -3551,9 +3560,6 @@ rb_thread_fd_select(int max, rb_fdset_t https://github.com/ruby/ruby/blob/trunk/thread.c#L3560
 #define POLLOUT_SET (POLLWRBAND | POLLWRNORM | POLLOUT | POLLERR)
 #define POLLEX_SET (POLLPRI)
 
-#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)
-
 #ifndef HAVE_PPOLL
 /* TODO: don't ignore sigmask */
 int

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

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