mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* internal.h (TIMET_MAX_PLUS_ONE): Defined.
* thread.c (double2timeval): Saturate out-of-range values. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bdc42b0ef3
commit
3dcdfcf884
3 changed files with 23 additions and 9 deletions
|
@ -1,3 +1,9 @@
|
|||
Wed Mar 27 00:28:45 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* internal.h (TIMET_MAX_PLUS_ONE): Defined.
|
||||
|
||||
* thread.c (double2timeval): Saturate out-of-range values.
|
||||
|
||||
Tue Mar 26 23:41:18 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* internal.h: Define TIMET_MAX and TIMET_MIN here.
|
||||
|
|
|
@ -22,6 +22,10 @@ extern "C" {
|
|||
#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)
|
||||
|
||||
#define TIMET_MAX_PLUS_ONE (~(time_t)0 <= 0 ? \
|
||||
((time_t)1 << (sizeof(time_t) * CHAR_BIT / 2)) * (double)((time_t)1 << (sizeof(time_t) * CHAR_BIT / 2 - 1)) : \
|
||||
((time_t)1 << (sizeof(time_t) * CHAR_BIT / 2)) * (double)((time_t)1 << (sizeof(time_t) * CHAR_BIT / 2)))
|
||||
|
||||
struct rb_deprecated_classext_struct {
|
||||
char conflict[sizeof(VALUE) * 3];
|
||||
};
|
||||
|
|
16
thread.c
16
thread.c
|
@ -916,18 +916,22 @@ double2timeval(double d)
|
|||
{
|
||||
struct timeval time;
|
||||
|
||||
if (isinf(d)) {
|
||||
if (TIMET_MAX_PLUS_ONE <= d) {
|
||||
time.tv_sec = TIMET_MAX;
|
||||
time.tv_usec = 0;
|
||||
return time;
|
||||
time.tv_usec = 999999;
|
||||
}
|
||||
|
||||
time.tv_sec = (int)d;
|
||||
time.tv_usec = (int)((d - (int)d) * 1e6);
|
||||
else if (d <= TIMET_MIN) {
|
||||
time.tv_sec = TIMET_MIN;
|
||||
time.tv_usec = 0;
|
||||
}
|
||||
else {
|
||||
time.tv_sec = (time_t)d;
|
||||
time.tv_usec = (int)((d - (time_t)d) * 1e6);
|
||||
if (time.tv_usec < 0) {
|
||||
time.tv_usec += (int)1e6;
|
||||
time.tv_sec -= 1;
|
||||
}
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue