summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-17 01:58:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-17 01:58:25 +0000
commit9e39bc1a088e0ac8cb6433c4daab03136253bf9d (patch)
treeef03743c6df014a10690cb2a1139693b3b76e892
parent08f52b05b2eac1eec3bc568f7b2cf4c730ebc462 (diff)
downloadruby-9e39bc1a088e0ac8cb6433c4daab03136253bf9d.tar.gz
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--thread.c23
2 files changed, 17 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index f1abd7a05d..ebcd95c46b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Apr 17 10:58:18 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@fsij.org>
* ext/socket/unixsocket.c (unix_send_io): Suppress a warning by clang.
diff --git a/thread.c b/thread.c
index 8a1e090160..280362d690 100644
--- a/thread.c
+++ b/thread.c
@@ -912,18 +912,19 @@ thread_value(VALUE self)
* 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 timeval tv, int spurious_check)
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++;