Skip to content

Commit

Permalink
* thread.c (double2timeval): convert the infinity to TIME_MAX to avoid
Browse files Browse the repository at this point in the history
  SEGV by Thread.new {}.join(Float::INFINITY) on
  Debian GNU/Linux (amd64).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
akr committed Mar 26, 2013
1 parent e1540cd commit 79f7521
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,3 +1,9 @@
Tue Mar 26 22:14:46 2013 Tanaka Akira <akr@fsij.org>

* 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@segment7.net>

* lib/rinda/tuplespace.rb: Only return tuple entry once on move,
Expand Down
12 changes: 9 additions & 3 deletions thread.c
Expand Up @@ -73,6 +73,9 @@
#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;

Expand Down Expand Up @@ -916,6 +919,12 @@ double2timeval(double d)
{
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) {
Expand Down Expand Up @@ -3551,9 +3560,6 @@ rb_thread_fd_select(int max, rb_fdset_t * read, rb_fdset_t * write, rb_fdset_t *
#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
Expand Down

0 comments on commit 79f7521

Please sign in to comment.