summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-30 21:08:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-30 21:08:42 +0000
commitb5583577d46e8aa1725840186e0f609cacec1bda (patch)
tree5d89a37803a6541376bfb34cea311ca6f2216708 /thread.c
parent77ff241fa0bc5f9db2606486f486a3de39f70718 (diff)
thread.c: TYPEOF_TIMEVAL_TV_SEC
* configure.in (TYPEOF_TIMEVAL_TV_SEC): check for x64-mingw, where timeval.tv_sec is not time_t. * thread.c (double2timeval): use TYPEOF_TIMEVAL_TV_SEC to get rid of overflow. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/thread.c b/thread.c
index 09c3b1d124..95b045fc54 100644
--- a/thread.c
+++ b/thread.c
@@ -915,18 +915,29 @@ thread_value(VALUE self)
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;
- if (TIMET_MAX_PLUS_ONE <= d) {
- time.tv_sec = TIMET_MAX;
+ if (TIMEVAL_SEC_MAX_PLUS_ONE <= d) {
+ time.tv_sec = TIMEVAL_SEC_MAX;
time.tv_usec = 999999;
}
- else if (d <= TIMET_MIN) {
- time.tv_sec = TIMET_MIN;
+ else if (d <= TIMEVAL_SEC_MIN) {
+ time.tv_sec = TIMEVAL_SEC_MIN;
time.tv_usec = 0;
}
else {
- time.tv_sec = (time_t)d;
+ time.tv_sec = (TYPEOF_TIMEVAL_TV_SEC)d;
time.tv_usec = (int)((d - (time_t)d) * 1e6);
if (time.tv_usec < 0) {
time.tv_usec += (int)1e6;