ruby-changes:19003
From: nobu <ko1@a...>
Date: Mon, 7 Mar 2011 09:18:46 +0900 (JST)
Subject: [ruby-changes:19003] Ruby:r31039 (trunk): fix of ext/date/date_core.
nobu 2011-03-07 08:38:31 +0900 (Mon, 07 Mar 2011) New Revision: 31039 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31039 Log: fix of ext/date/date_core. * ext/date/date_core.c (DateTimeData): should not use bare 'long long' and 'long double', which are not defined by C89. * ext/date/date_core.c (dt_lite_plus): get rid of overflow at casting down double to integer. Modified files: trunk/ext/date/date_core.c trunk/ext/date/extconf.rb Index: ext/date/date_core.c =================================================================== --- ext/date/date_core.c (revision 31038) +++ ext/date/date_core.c (revision 31039) @@ -14,13 +14,6 @@ #include RUBY_EXTCONF_H #endif -#ifndef HAVE_FLOORL -#define floorl(x) ((long double)floor((double)(x))) -#endif -#ifndef HAVE_ROUNDL -#define roundl(x) ((long double)round((double)(x))) -#endif - #define LIGHT_MODE (1 << 0) #define HAVE_JD (1 << 1) #define HAVE_DF (1 << 2) @@ -89,7 +82,7 @@ unsigned flags; long jd; /* as utc */ int df; /* as utc, in secs */ - long long sf; /* in nano secs */ + long sf; /* in nano secs */ int of; /* in secs */ double sg; /* decoded as local */ @@ -1699,8 +1692,8 @@ if (light_mode_p(adat) && light_mode_p(bdat)) { - long d; - int df, sf; + long d, sf; + int df; VALUE r; get_dt_jd(adat); @@ -2075,7 +2068,7 @@ inline static VALUE dt_lite_s_new_internal(VALUE klass, long jd, int df, - long long sf, int of, double sg, + long sf, int of, double sg, int y, int m, int d, int h, int min, int s, unsigned flags) @@ -2103,7 +2096,7 @@ static VALUE dt_lite_s_new_internal_wo_civil(VALUE klass, long jd, int df, - long long sf, int of, double sg, + long sf, int of, double sg, unsigned flags) { return dt_lite_s_new_internal(klass, jd, df, sf, of, sg, @@ -2443,12 +2436,11 @@ struct timespec ts; #else struct timeval tv; - time_t sec; #endif + time_t sec; struct tm tm; - long y; + long y, sf; int m, d, h, min, s, of; - long long sf; rb_scan_args(argc, argv, "01", &vsg); @@ -2460,13 +2452,13 @@ #ifdef HAVE_CLOCK_GETTIME if (clock_gettime(CLOCK_REALTIME, &ts) == -1) rb_sys_fail("clock_gettime"); - localtime_r(&ts.tv_sec, &tm); + sec = ts.tv_sec; #else if (gettimeofday(&tv, NULL) == -1) rb_sys_fail("gettimeofday"); sec = tv.tv_sec; - localtime_r(&sec, &tm); #endif + localtime_r(&sec, &tm); y = tm.tm_year + 1900; m = tm.tm_mon + 1; @@ -2975,10 +2967,9 @@ break; case T_FLOAT: { - long jd, df; - long long sf; - long double o; - int s; + long sf; + double jd, o, tmp; + int s, df; get_dt1(self); get_dt_jd(dat); @@ -2994,13 +2985,12 @@ else s = +1; - jd = (long)floorl(o); - o = o - jd; + o = modf(o, &jd); o *= DAY_IN_SECONDS; - df = (long)floorl(o); - o = o - df; + o = modf(o, &tmp); + df = (int)tmp; o *= SECOND_IN_NANOSECONDS; - sf = (long)roundl(o); + sf = (long)round(o); if (s < 0) { jd = -jd; @@ -3032,7 +3022,7 @@ if (LIGHTABLE_JD(jd) && jd >= dat->l.sg) return dt_lite_s_new_internal(CLASS_OF(self), - jd, + (long)jd, df, sf, dat->l.of, Index: ext/date/extconf.rb =================================================================== --- ext/date/extconf.rb (revision 31038) +++ ext/date/extconf.rb (revision 31039) @@ -1,4 +1,2 @@ require 'mkmf' -have_func('floorl', 'math.h') -have_func('roundl', 'math.h') create_makefile('date_core') -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/