ruby-changes:27960
From: nobu <ko1@a...>
Date: Sun, 31 Mar 2013 06:08:58 +0900 (JST)
Subject: [ruby-changes:27960] nobu:r40012 (trunk): thread.c: TYPEOF_TIMEVAL_TV_SEC
nobu 2013-03-31 06:08:42 +0900 (Sun, 31 Mar 2013) New Revision: 40012 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40012 Log: 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. Modified files: trunk/configure.in trunk/thread.c Index: configure.in =================================================================== --- configure.in (revision 40011) +++ configure.in (revision 40012) @@ -1461,6 +1461,24 @@ AC_CHECK_TYPES([struct timeval], [], [], https://github.com/ruby/ruby/blob/trunk/configure.in#L1461 @%:@include <sys/time.h> @%:@endif]) +if test "${ac_cv_type_struct_timeval}" = yes; then + RUBY_CHECK_SIZEOF([struct timeval.tv_sec], [time_t long "long long"], [], + [@%:@ifdef HAVE_TIME_H +@%:@include <time.h> +@%:@endif +@%:@ifdef HAVE_SYS_TIME_H +@%:@include <sys/time.h> +@%:@endif]) + AS_CASE(${ac_cv_sizeof_struct_timeval_tv_sec}, + [SIZEOF_INT], [t=int], + [SIZEOF_LONG], [t=long], + [SIZEOF_LONG_LONG], [t=LONG_LONG], + [t=]) + if test "${t}" != ""; then + AC_DEFINE_UNQUOTED(TYPEOF_TIMEVAL_TV_SEC, [$t]) + fi +fi + AC_CHECK_TYPES([struct timespec], [], [], [@%:@ifdef HAVE_TIME_H @%:@include <time.h> @%:@endif Index: thread.c =================================================================== --- thread.c (revision 40011) +++ thread.c (revision 40012) @@ -915,18 +915,29 @@ thread_value(VALUE self) https://github.com/ruby/ruby/blob/trunk/thread.c#L915 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/