From e88a692a884a2c9d5349e1e94da3b0d77247adc2 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 27 Apr 2013 03:30:50 +0000 Subject: * thread.c (TIMEVAL_SEC_MAX, TIMEVAL_SEC_MIN): Consider environments, sizeof(time_t) is smaller than sizeof(tv_sec), such as OpenBSD 5.2 (amd64). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'thread.c') diff --git a/thread.c b/thread.c index 280362d690..36414bacf8 100644 --- a/thread.c +++ b/thread.c @@ -912,10 +912,20 @@ thread_value(VALUE self) * Thread Scheduling */ +/* + * The type of tv_sec in struct timeval is time_t in POSIX. + * But several systems violates POSIX. + * + * OpenBSD 5.2 (amd64): + * time_t: int (signed 32bit integer) + * tv_sec: long (signed 64bit integer) + */ + #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) +# define TIMEVAL_SEC_MAXBIT \ + (((TYPEOF_TIMEVAL_TV_SEC)1) << (sizeof(TYPEOF_TIMEVAL_TV_SEC) * CHAR_BIT - 2)) +# define TIMEVAL_SEC_MAX (TIMEVAL_SEC_MAXBIT | (TIMEVAL_SEC_MAXBIT-1)) +# define TIMEVAL_SEC_MIN (-TIMEVAL_SEC_MAX-1) #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) -- cgit v1.2.3