ruby-changes:30572
From: akr <ko1@a...>
Date: Thu, 22 Aug 2013 20:19:55 +0900 (JST)
Subject: [ruby-changes:30572] akr:r42651 (trunk): * process.c (unsigned_clock_t): Defined.
akr 2013-08-22 20:19:49 +0900 (Thu, 22 Aug 2013) New Revision: 42651 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42651 Log: * process.c (unsigned_clock_t): Defined. (rb_clock_gettime): Consider clock_t overflow for ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID. * configure.in: Check the size of clock_t. Modified files: trunk/ChangeLog trunk/configure.in trunk/process.c Index: configure.in =================================================================== --- configure.in (revision 42650) +++ configure.in (revision 42651) @@ -1168,6 +1168,7 @@ RUBY_CHECK_SIZEOF(void*, [int long "long https://github.com/ruby/ruby/blob/trunk/configure.in#L1168 RUBY_CHECK_SIZEOF(float) RUBY_CHECK_SIZEOF(double) RUBY_CHECK_SIZEOF(time_t, [long "long long"], [], [@%:@include <time.h>]) +RUBY_CHECK_SIZEOF(clock_t) AC_DEFUN([RUBY_CHECK_PRINTF_PREFIX], [ AC_CACHE_CHECK([for printf prefix for $1], [rb_cv_pri_prefix_]AS_TR_SH($1),[ Index: ChangeLog =================================================================== --- ChangeLog (revision 42650) +++ ChangeLog (revision 42651) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Aug 22 20:14:59 2013 Tanaka Akira <akr@f...> + + * process.c (unsigned_clock_t): Defined. + (rb_clock_gettime): Consider clock_t overflow for + ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID. + + * configure.in: Check the size of clock_t. + Thu Aug 22 16:22:48 2013 Koichi Sasada <ko1@a...> * compile.c (build_postexe_iseq): fix to setup the local table. Index: process.c =================================================================== --- process.c (revision 42650) +++ process.c (revision 42651) @@ -196,6 +196,14 @@ static rb_gid_t obj2gid(VALUE id); https://github.com/ruby/ruby/blob/trunk/process.c#L196 # endif #endif +#if SIZEOF_CLOCK_T == SIZEOF_INT +typedef unsigned int unsigned_clock_t; +#elif SIZEOF_CLOCK_T == SIZEOF_LONG +typedef unsigned long unsigned_clock_t; +#elif defined(HAVE_LONG_LONG) && SIZEOF_CLOCK_T == SIZEOF_LONG_LONG +typedef unsigned LONG_LONG unsigned_clock_t; +#endif + /* * call-seq: * Process.pid -> fixnum @@ -6886,15 +6894,18 @@ rb_clock_gettime(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L6894 #define RUBY_ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID \ ID2SYM(rb_intern("ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID")) if (clk_id == RUBY_ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID) { - double ns; + double s, ns; clock_t c; + unsigned_clock_t uc; c = clock(); errno = 0; if (c == (clock_t)-1) rb_sys_fail("clock"); - ns = c * (1e9 / CLOCKS_PER_SEC); - ts.tv_sec = (time_t)(ns*1e-9); - ts.tv_nsec = ns - ts.tv_sec*1e9; + uc = (unsigned_clock_t)c; + ns = (uc*1e9) / CLOCKS_PER_SEC; /* uc*1e9 doesn't lose data if clock_t is 32bit. */ + s = floor(ns*1e-9); + ts.tv_sec = (time_t)s; + ts.tv_nsec = ns - s*1e9; goto success; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/