From e358888d5e22344429ee7d5589b5053e0a817afd Mon Sep 17 00:00:00 2001 From: tadf Date: Fri, 25 Mar 2011 13:01:06 +0000 Subject: [PATCH] * ext/date/date_core.c: should not force cast with macros. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ ext/date/date_core.c | 20 ++++++++++---------- ext/date/date_strftime.c | 7 ++++--- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4ddb96a804..e1f9d10e7e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Mar 25 21:59:45 2011 Tadayoshi Funaba + + * ext/date/date_core.c: should not force cast with macros. + Fri Mar 25 21:56:10 2011 Tanaka Akira * ext/sdbm/init.c: parenthesize macro arguments. diff --git a/ext/date/date_core.c b/ext/date/date_core.c index e75c666e14..c20079b2e9 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -42,10 +42,10 @@ #define DAY_IN_NANOSECONDS 86400000000000LL /* copied from time.c */ -#define NDIV(x,y) ((int)(-(-((x)+1)/(y))-1)) -#define NMOD(x,y) ((int)((y)-(-((x)+1)%(y))-1)) -#define DIV(n,d) ((int)((n)<0 ? NDIV((n),(d)) : (n)/(d))) -#define MOD(n,d) ((int)((n)<0 ? NMOD((n),(d)) : (n)%(d))) +#define NDIV(x,y) (-(-((x)+1)/(y))-1) +#define NMOD(x,y) ((y)-(-((x)+1)%(y))-1) +#define DIV(n,d) ((n)<0 ? NDIV((n),(d)) : (n)/(d)) +#define MOD(n,d) ((n)<0 ? NMOD((n),(d)) : (n)%(d)) union DateData { @@ -338,8 +338,8 @@ jd_to_commercial(long jd, double sg, int *ry, int *rw, int *rd) commercial_to_jd(a, 1, 1, sg, &rjd2, &ns2); *ry = a; } - *rw = 1 + DIV(jd - rjd2, 7); - *rd = MOD(jd + 1, 7); + *rw = 1 + (int)DIV(jd - rjd2, 7); + *rd = (int)MOD(jd + 1, 7); if (*rd == 0) *rd = 7; } @@ -368,8 +368,8 @@ jd_to_weeknum(long jd, int f, double sg, int *ry, int *rw, int *rd) find_fdoy(*ry, sg, &rjd, &ns); rjd += 6; j = jd - (rjd - MOD((rjd - f) + 1, 7)) + 7; - *rw = DIV(j, 7); - *rd = MOD(j, 7); + *rw = (int)DIV(j, 7); + *rd = (int)MOD(j, 7); } #ifndef NDEBUG @@ -403,7 +403,7 @@ jd_to_nth_kday(long jd, double sg, int *ry, int *rm, int *rn, int *rk) jd_to_civil(jd, sg, ry, rm, &rd); find_fdom(*ry, *rm, sg, &rjd, &ns2); - *rn = DIV(jd - rjd, 7) + 1; + *rn = (int)DIV(jd - rjd, 7) + 1; *rk = jd_to_wday(jd); } #endif @@ -585,7 +585,7 @@ time_to_df(int h, int min, int s) inline static int jd_to_wday(long jd) { - return MOD(jd + 1, 7); + return (int)MOD(jd + 1, 7); } static int diff --git a/ext/date/date_strftime.c b/ext/date/date_strftime.c index f30f6103ca..774d8acb8b 100644 --- a/ext/date/date_strftime.c +++ b/ext/date/date_strftime.c @@ -487,13 +487,14 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format, case 'z': /* time zone offset east of GMT e.g. -0600 */ SKIP_MODIFIER_EO; { - int aoff, hl, hw; + long aoff; + int hl, hw; off = NUM2LONG(rb_funcall(vtm->utc_offset, rb_intern("round"), 0)); - aoff = (int)off; + aoff = off; if (aoff < 0) - aoff = (int)-off; + aoff = -off; if ((aoff / 3600) < 10) hl = 1;