mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
29246c34eb
commit
35c9d383a9
2 changed files with 17 additions and 29 deletions
|
@ -14,13 +14,6 @@
|
||||||
#include RUBY_EXTCONF_H
|
#include RUBY_EXTCONF_H
|
||||||
#endif
|
#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 LIGHT_MODE (1 << 0)
|
||||||
#define HAVE_JD (1 << 1)
|
#define HAVE_JD (1 << 1)
|
||||||
#define HAVE_DF (1 << 2)
|
#define HAVE_DF (1 << 2)
|
||||||
|
@ -89,7 +82,7 @@ union DateTimeData
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
long jd; /* as utc */
|
long jd; /* as utc */
|
||||||
int df; /* as utc, in secs */
|
int df; /* as utc, in secs */
|
||||||
long long sf; /* in nano secs */
|
long sf; /* in nano secs */
|
||||||
int of; /* in secs */
|
int of; /* in secs */
|
||||||
double sg;
|
double sg;
|
||||||
/* decoded as local */
|
/* decoded as local */
|
||||||
|
@ -1699,8 +1692,8 @@ minus_dd(VALUE self, VALUE other)
|
||||||
|
|
||||||
if (light_mode_p(adat) &&
|
if (light_mode_p(adat) &&
|
||||||
light_mode_p(bdat)) {
|
light_mode_p(bdat)) {
|
||||||
long d;
|
long d, sf;
|
||||||
int df, sf;
|
int df;
|
||||||
VALUE r;
|
VALUE r;
|
||||||
|
|
||||||
get_dt_jd(adat);
|
get_dt_jd(adat);
|
||||||
|
@ -2075,7 +2068,7 @@ d_right_cache(VALUE self)
|
||||||
|
|
||||||
inline static VALUE
|
inline static VALUE
|
||||||
dt_lite_s_new_internal(VALUE klass, long jd, int df,
|
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 y, int m, int d,
|
||||||
int h, int min, int s,
|
int h, int min, int s,
|
||||||
unsigned flags)
|
unsigned flags)
|
||||||
|
@ -2103,7 +2096,7 @@ dt_lite_s_new_internal(VALUE klass, long jd, int df,
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
dt_lite_s_new_internal_wo_civil(VALUE klass, long jd, int df,
|
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)
|
unsigned flags)
|
||||||
{
|
{
|
||||||
return dt_lite_s_new_internal(klass, jd, df, sf, of, sg,
|
return dt_lite_s_new_internal(klass, jd, df, sf, of, sg,
|
||||||
|
@ -2443,12 +2436,11 @@ datetime_s_now(int argc, VALUE *argv, VALUE klass)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
#else
|
#else
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
time_t sec;
|
|
||||||
#endif
|
#endif
|
||||||
|
time_t sec;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
long y;
|
long y, sf;
|
||||||
int m, d, h, min, s, of;
|
int m, d, h, min, s, of;
|
||||||
long long sf;
|
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "01", &vsg);
|
rb_scan_args(argc, argv, "01", &vsg);
|
||||||
|
|
||||||
|
@ -2460,13 +2452,13 @@ datetime_s_now(int argc, VALUE *argv, VALUE klass)
|
||||||
#ifdef HAVE_CLOCK_GETTIME
|
#ifdef HAVE_CLOCK_GETTIME
|
||||||
if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
|
if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
|
||||||
rb_sys_fail("clock_gettime");
|
rb_sys_fail("clock_gettime");
|
||||||
localtime_r(&ts.tv_sec, &tm);
|
sec = ts.tv_sec;
|
||||||
#else
|
#else
|
||||||
if (gettimeofday(&tv, NULL) == -1)
|
if (gettimeofday(&tv, NULL) == -1)
|
||||||
rb_sys_fail("gettimeofday");
|
rb_sys_fail("gettimeofday");
|
||||||
sec = tv.tv_sec;
|
sec = tv.tv_sec;
|
||||||
localtime_r(&sec, &tm);
|
|
||||||
#endif
|
#endif
|
||||||
|
localtime_r(&sec, &tm);
|
||||||
|
|
||||||
y = tm.tm_year + 1900;
|
y = tm.tm_year + 1900;
|
||||||
m = tm.tm_mon + 1;
|
m = tm.tm_mon + 1;
|
||||||
|
@ -2975,10 +2967,9 @@ dt_lite_plus(VALUE self, VALUE other)
|
||||||
break;
|
break;
|
||||||
case T_FLOAT:
|
case T_FLOAT:
|
||||||
{
|
{
|
||||||
long jd, df;
|
long sf;
|
||||||
long long sf;
|
double jd, o, tmp;
|
||||||
long double o;
|
int s, df;
|
||||||
int s;
|
|
||||||
|
|
||||||
get_dt1(self);
|
get_dt1(self);
|
||||||
get_dt_jd(dat);
|
get_dt_jd(dat);
|
||||||
|
@ -2994,13 +2985,12 @@ dt_lite_plus(VALUE self, VALUE other)
|
||||||
else
|
else
|
||||||
s = +1;
|
s = +1;
|
||||||
|
|
||||||
jd = (long)floorl(o);
|
o = modf(o, &jd);
|
||||||
o = o - jd;
|
|
||||||
o *= DAY_IN_SECONDS;
|
o *= DAY_IN_SECONDS;
|
||||||
df = (long)floorl(o);
|
o = modf(o, &tmp);
|
||||||
o = o - df;
|
df = (int)tmp;
|
||||||
o *= SECOND_IN_NANOSECONDS;
|
o *= SECOND_IN_NANOSECONDS;
|
||||||
sf = (long)roundl(o);
|
sf = (long)round(o);
|
||||||
|
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
jd = -jd;
|
jd = -jd;
|
||||||
|
@ -3032,7 +3022,7 @@ dt_lite_plus(VALUE self, VALUE other)
|
||||||
|
|
||||||
if (LIGHTABLE_JD(jd) && jd >= dat->l.sg)
|
if (LIGHTABLE_JD(jd) && jd >= dat->l.sg)
|
||||||
return dt_lite_s_new_internal(CLASS_OF(self),
|
return dt_lite_s_new_internal(CLASS_OF(self),
|
||||||
jd,
|
(long)jd,
|
||||||
df,
|
df,
|
||||||
sf,
|
sf,
|
||||||
dat->l.of,
|
dat->l.of,
|
||||||
|
|
|
@ -1,4 +1,2 @@
|
||||||
require 'mkmf'
|
require 'mkmf'
|
||||||
have_func('floorl', 'math.h')
|
|
||||||
have_func('roundl', 'math.h')
|
|
||||||
create_makefile('date_core')
|
create_makefile('date_core')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue