Issue #4529 has been reported by Yui NARUSE.

----------------------------------------
Feature #4529: date_core ??? long ???
http://redmine.ruby-lang.org/issues/4529

Author: Yui NARUSE
Status: Assigned
Priority: Normal
Assignee: tadayoshi funaba
Category: ext
Target version: 


?????????????????????????????????? date_core ?????????? ext 中?? shorten-64-to-32 ??????????????????
???????????????? date_core ????????????????????????????????????????????年?? long ???????????????? int ??????????????????????????????

int ??? long ???混??????????????long ?????? int ??????????????????????????起??????????????????
???????????? long ???
* ?????????????????????? (int ??? ?????????????????????????????CRuby ???? 32bit ??????確??????????)
* long ??? mswin64 ???????????????????????????????Unix ??人??????????????????????温??????
????????????????念???????????????????????????????????????int ?????????????int64_t ???????????????????????????????????????????
(CRuby ??? C90 ?????????int64_t ??? configure ????義?????????)

??????? int ??統???????????????????????以????????????

diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index c20079b..75c20d3 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -59,7 +59,7 @@ union DateData
     } r;
     struct {
 	unsigned flags;
-	long jd;	/* as utc */
+	int jd;	/* as utc */
 	double sg;
 	/* decoded as utc=local */
 	int year;
@@ -80,9 +80,9 @@ union DateTimeData
     } r;
     struct {
 	unsigned flags;
-	long jd;	/* as utc */
+	int jd;	/* as utc */
 	int df;		/* as utc, in secs */
-	long sf;	/* in nano secs */
+	int sf;	/* in nano secs */
 	int of;		/* in secs */
 	double sg;
 	/* decoded as local */
@@ -185,10 +185,10 @@ static VALUE cDate, cDateTime;
 static VALUE rzero, rhalf, day_in_nanoseconds;
 
 static int valid_civil_p(int y, int m, int d, double sg,
-			 int *rm, int *rd, long *rjd, int *ns);
+			 int *rm, int *rd, int *rjd, int *ns);
 
 static int
-find_fdoy(int y, double sg, long *rjd, int *ns)
+find_fdoy(int y, double sg, int *rjd, int *ns)
 {
     int d, rm, rd;
 
@@ -199,7 +199,7 @@ find_fdoy(int y, double sg, long *rjd, int *ns)
 }
 
 static int
-find_ldoy(int y, double sg, long *rjd, int *ns)
+find_ldoy(int y, double sg, int *rjd, int *ns)
 {
     int i, rm, rd;
 
@@ -211,7 +211,7 @@ find_ldoy(int y, double sg, long *rjd, int *ns)
 
 #ifndef NDEBUG
 static int
-find_fdom(int y, int m, double sg, long *rjd, int *ns)
+find_fdom(int y, int m, double sg, int *rjd, int *ns)
 {
     int d, rm, rd;
 
@@ -223,7 +223,7 @@ find_fdom(int y, int m, double sg, long *rjd, int *ns)
 #endif
 
 static int
-find_ldom(int y, int m, double sg, long *rjd, int *ns)
+find_ldom(int y, int m, double sg, int *rjd, int *ns)
 {
     int i, rm, rd;
 
@@ -234,7 +234,7 @@ find_ldom(int y, int m, double sg, long *rjd, int *ns)
 }
 
 static void
-civil_to_jd(int y, int m, int d, double sg, long *rjd, int *ns)
+civil_to_jd(int y, int m, int d, double sg, int *rjd, int *ns)
 {
     double a, b, jd;
 
@@ -254,11 +254,11 @@ civil_to_jd(int y, int m, int d, double sg, long *rjd, int *ns)
     else
 	*ns = 1;
 
-    *rjd = (long)jd;
+    *rjd = jd;
 }
 
 static void
-jd_to_civil(long jd, double sg, int *ry, int *rm, int *rdom)
+jd_to_civil(int jd, double sg, int *ry, int *rm, int *rdom)
 {
     double x, a, b, c, d, e, y, m, dom;
 
@@ -288,7 +288,7 @@ jd_to_civil(long jd, double sg, int *ry, int *rm, int *rdom)
 }
 
 static void
-ordinal_to_jd(int y, int d, double sg, long *rjd, int *ns)
+ordinal_to_jd(int y, int d, double sg, int *rjd, int *ns)
 {
     int ns2;
 
@@ -298,20 +298,20 @@ ordinal_to_jd(int y, int d, double sg, long *rjd, int *ns)
 }
 
 static void
-jd_to_ordinal(long jd, double sg, int *ry, int *rd)
+jd_to_ordinal(int jd, double sg, int *ry, int *rd)
 {
     int rm2, rd2, ns;
-    long rjd;
+    int rjd;
 
     jd_to_civil(jd, sg, ry, &rm2, &rd2);
     find_fdoy(*ry, sg, &rjd, &ns);
-    *rd = (int)(jd - rjd) + 1;
+    *rd = jd - rjd + 1;
 }
 
 static void
-commercial_to_jd(int y, int w, int d, double sg, long *rjd, int *ns)
+commercial_to_jd(int y, int w, int d, double sg, int *rjd, int *ns)
 {
-    long rjd2;
+    int rjd2;
     int ns2;
 
     find_fdoy(y, sg, &rjd2, &ns2);
@@ -324,10 +324,10 @@ commercial_to_jd(int y, int w, int d, double sg, long *rjd, int *ns)
 }
 
 static void
-jd_to_commercial(long jd, double sg, int *ry, int *rw, int *rd)
+jd_to_commercial(int jd, double sg, int *ry, int *rw, int *rd)
 {
     int ry2, rm2, rd2, a, ns2;
-    long rjd2;
+    int rjd2;
 
     jd_to_civil(jd - 3, sg, &ry2, &rm2, &rd2);
     a = ry2;
@@ -346,9 +346,9 @@ jd_to_commercial(long jd, double sg, int *ry, int *rw, int *rd)
 
 #ifndef NDEBUG
 static void
-weeknum_to_jd(int y, int w, int d, int f, double sg, long *rjd, int *ns)
+weeknum_to_jd(int y, int w, int d, int f, double sg, int *rjd, int *ns)
 {
-    long rjd2;
+    int rjd2;
     int ns2;
 
     find_fdoy(y, sg, &rjd2, &ns2);
@@ -359,10 +359,10 @@ weeknum_to_jd(int y, int w, int d, int f, double sg, long *rjd, int *ns)
 #endif
 
 static void
-jd_to_weeknum(long jd, int f, double sg, int *ry, int *rw, int *rd)
+jd_to_weeknum(int jd, int f, double sg, int *ry, int *rw, int *rd)
 {
     int rm, rd2, ns;
-    long rjd, j;
+    int rjd, j;
 
     jd_to_civil(jd, sg, ry, &rm, &rd2);
     find_fdoy(*ry, sg, &rjd, &ns);
@@ -374,9 +374,9 @@ jd_to_weeknum(long jd, int f, double sg, int *ry, int *rw, int *rd)
 
 #ifndef NDEBUG
 static void
-nth_kday_to_jd(int y, int m, int n, int k, double sg, long *rjd, int *ns)
+nth_kday_to_jd(int y, int m, int n, int k, double sg, int *rjd, int *ns)
 {
-    long rjd2;
+    int rjd2;
     int ns2;
 
     if (n > 0) {
@@ -393,13 +393,13 @@ nth_kday_to_jd(int y, int m, int n, int k, double sg, long *rjd, int *ns)
 #endif
 
 #ifndef NDEBUG
-inline static int jd_to_wday(long jd);
+inline static int jd_to_wday(int jd);
 
 static void
-jd_to_nth_kday(long jd, double sg, int *ry, int *rm, int *rn, int *rk)
+jd_to_nth_kday(int jd, double sg, int *ry, int *rm, int *rn, int *rk)
 {
     int rd, ns2;
-    long rjd;
+    int rjd;
 
     jd_to_civil(jd, sg, ry, rm, &rd);
     find_fdom(*ry, *rm, sg, &rjd, &ns2);
@@ -410,12 +410,12 @@ jd_to_nth_kday(long jd, double sg, int *ry, int *rm, int *rn, int *rk)
 
 static int
 valid_ordinal_p(int y, int d, double sg,
-		int *rd, long *rjd, int *ns)
+		int *rd, int *rjd, int *ns)
 {
     int ry2, rd2;
 
     if (d < 0) {
-	long rjd2;
+	int rjd2;
 	int ns2;
 
 	if (!find_ldoy(y, sg, &rjd2, &ns2))
@@ -469,7 +469,7 @@ valid_gregorian_p(int y, int m, int d, int *rm, int *rd)
 
 static int
 valid_civil_p(int y, int m, int d, double sg,
-	      int *rm, int *rd, long *rjd, int *ns)
+	      int *rm, int *rd, int *rjd, int *ns)
 {
     int ry;
 
@@ -492,14 +492,14 @@ valid_civil_p(int y, int m, int d, double sg,
 
 static int
 valid_commercial_p(int y, int w, int d, double sg,
-		   int *rw, int *rd, long *rjd, int *ns)
+		   int *rw, int *rd, int *rjd, int *ns)
 {
     int ns2, ry2, rw2, rd2;
 
     if (d < 0)
 	d += 8;
     if (w < 0) {
-	long rjd2;
+	int rjd2;
 
 	commercial_to_jd(y + 1, 1, 1, sg, &rjd2, &ns2);
 	jd_to_commercial(rjd2 + w * 7, sg, &ry2, &rw2, &rd2);
@@ -554,8 +554,8 @@ df_utc_to_local(int df, int of)
     return df;
 }
 
-inline static long
-jd_local_to_utc(long jd, int df, int of)
+inline static int
+jd_local_to_utc(int jd, int df, int of)
 {
     df -= of;
     if (df < 0)
@@ -565,8 +565,8 @@ jd_local_to_utc(long jd, int df, int of)
     return jd;
 }
 
-inline static long
-jd_utc_to_local(long jd, int df, int of)
+inline static int
+jd_utc_to_local(int jd, int df, int of)
 {
     df += of;
     if (df < 0)
@@ -583,7 +583,7 @@ time_to_df(int h, int min, int s)
 }
 
 inline static int
-jd_to_wday(long jd)
+jd_to_wday(int jd)
 {
     return (int)MOD(jd + 1, 7);
 }
@@ -651,7 +651,7 @@ inline static void
 get_d_jd(union DateData *x)
 {
     if (!have_jd_p(x)) {
-	long jd;
+	int jd;
 	int ns;
 
 	assert(have_civil_p(x));
@@ -711,7 +711,7 @@ inline static void
 get_dt_jd(union DateTimeData *x)
 {
     if (!have_jd_p(x)) {
-	long jd;
+	int jd;
 	int ns;
 
 	assert(have_civil_p(x));
@@ -730,7 +730,7 @@ inline static void
 get_dt_civil(union DateTimeData *x)
 {
     if (!have_civil_p(x)) {
-	long jd;
+	int jd;
 	int y, m, d;
 
 	assert(have_jd_p(x));
@@ -745,7 +745,7 @@ get_dt_civil(union DateTimeData *x)
     }
 }
 
-inline static long
+inline static int
 local_jd(union DateTimeData *x)
 {
     assert(have_jd_p(x));
@@ -835,7 +835,7 @@ date_s_valid_civil_p(int argc, VALUE *argv, VALUE klass)
 	return Qtrue;
     }
     else {
-	long jd;
+	int jd;
 	int ns;
 
 	if (!valid_civil_p(y, m, d, sg, &rm, &rd, &jd, &ns))
@@ -876,7 +876,7 @@ date_s_valid_ordinal_p(int argc, VALUE *argv, VALUE klass)
     }
 
     {
-	long jd;
+	int jd;
 	int ns;
 
 	if (!valid_ordinal_p(y, d, sg, &rd, &jd, &ns))
@@ -921,7 +921,7 @@ date_s_valid_commercial_p(int argc, VALUE *argv, VALUE klass)
     }
 
     {
-	long jd;
+	int jd;
 	int ns;
 
 	if (!valid_commercial_p(y, w, d, sg, &rw, &rd, &jd, &ns))
@@ -960,7 +960,7 @@ d_right_s_new_internal(VALUE klass, VALUE ajd, VALUE of, VALUE sg,
 }
 
 inline static VALUE
-d_lite_s_new_internal(VALUE klass, long jd, double sg,
+d_lite_s_new_internal(VALUE klass, int jd, double sg,
 		      int y, int m, int d, unsigned flags)
 {
     union DateData *dat;
@@ -979,7 +979,7 @@ d_lite_s_new_internal(VALUE klass, long jd, double sg,
 }
 
 static VALUE
-d_lite_s_new_internal_wo_civil(VALUE klass, long jd, double sg,
+d_lite_s_new_internal_wo_civil(VALUE klass, int jd, double sg,
 			       unsigned flags)
 {
     return d_lite_s_new_internal(klass, jd, sg, 0, 0, 0, flags);
@@ -1012,7 +1012,7 @@ static VALUE
 d_lite_s_new_l_bang(int argc, VALUE *argv, VALUE klass)
 {
     VALUE vjd, vsg;
-    long jd;
+    int jd;
     double sg;
 
     rb_scan_args(argc, argv, "02", &vjd, &vsg);
@@ -1022,7 +1022,7 @@ d_lite_s_new_l_bang(int argc, VALUE *argv, VALUE klass)
     else {
 	if (!FIXNUM_P(vjd))
 	    rb_raise(rb_eArgError, "cannot create");
-	jd = NUM2LONG(vjd);
+	jd = NUM2INT(vjd);
 	if (!LIGHTABLE_JD(jd))
 	    rb_raise(rb_eArgError, "cannot create");
     }
@@ -1062,7 +1062,7 @@ static VALUE
 date_s_jd(int argc, VALUE *argv, VALUE klass)
 {
     VALUE vjd, vsg;
-    long jd;
+    int jd;
     double sg;
 
     rb_scan_args(argc, argv, "02", &vjd, &vsg);
@@ -1076,7 +1076,7 @@ date_s_jd(int argc, VALUE *argv, VALUE klass)
 	sg = ITALY;
 
     if (argc >= 1) {
-	jd = NUM2LONG(vjd);
+	jd = NUM2INT(vjd);
 	if (!LIGHTABLE_JD(jd))
 	    return cforwardv("jd_r");
     }
@@ -1136,7 +1136,7 @@ date_s_ordinal(int argc, VALUE *argv, VALUE klass)
     }
 
     {
-	long jd;
+	int jd;
 	int ns;
 
 	if (!valid_ordinal_p(y, d, sg, &rd, &jd, &ns))
@@ -1212,7 +1212,7 @@ date_s_civil(int argc, VALUE *argv, VALUE klass)
 				     LIGHT_MODE | HAVE_CIVIL);
     }
     else {
-	long jd;
+	int jd;
 	int ns;
 
 	if (!valid_civil_p(y, m, d, sg, &rm, &rd, &jd, &ns))
@@ -1281,7 +1281,7 @@ date_s_commercial(int argc, VALUE *argv, VALUE klass)
     }
 
     {
-	long jd;
+	int jd;
 	int ns;
 
 	if (!valid_commercial_p(y, w, d, sg, &rw, &rd, &jd, &ns))
@@ -1321,7 +1321,7 @@ date_s_today(int argc, VALUE *argv, VALUE klass)
     double sg;
     time_t t;
     struct tm tm;
-    long y;
+    int y;
     int m, d;
 
     rb_scan_args(argc, argv, "01", &vsg);
@@ -1343,15 +1343,15 @@ date_s_today(int argc, VALUE *argv, VALUE klass)
 	rb_raise(rb_eArgError, "cannot create");
 
     if (isinf(sg) && sg < 0)
-	return d_lite_s_new_internal(klass, 0, sg, (int)y, m, d,
+	return d_lite_s_new_internal(klass, 0, sg, y, m, d,
 				     LIGHT_MODE | HAVE_CIVIL);
     else {
-	long jd;
+	int jd;
 	int ns;
 
-	civil_to_jd((int)y, m, d, sg, &jd, &ns);
+	civil_to_jd(y, m, d, sg, &jd, &ns);
 
-	return d_lite_s_new_internal(klass, jd, sg, (int)y, m, d,
+	return d_lite_s_new_internal(klass, jd, sg, y, m, d,
 				     LIGHT_MODE | HAVE_JD | HAVE_CIVIL);
     }
 }
@@ -1388,7 +1388,7 @@ d_lite_amjd(VALUE self)
 	return iforward0("amjd_r");
     {
 	get_d_jd(dat);
-	return rb_rational_new1(LONG2NUM(dat->l.jd - 2400001L));
+	return rb_rational_new1(INT2NUM(dat->l.jd - 2400001));
     }
 }
 
@@ -1424,7 +1424,7 @@ d_lite_mjd(VALUE self)
 	return iforward0("mjd_r");
     {
 	get_d_jd(dat);
-	return LONG2NUM(dat->l.jd - 2400001L);
+	return INT2NUM(dat->l.jd - 2400001);
     }
 }
 
@@ -1442,7 +1442,7 @@ d_lite_ld(VALUE self)
 	return iforward0("ld_r");
     {
 	get_d_jd(dat);
-	return LONG2NUM(dat->l.jd - 2299160L);
+	return INT2NUM(dat->l.jd - 2299160);
     }
 }
 
@@ -1920,11 +1920,11 @@ d_lite_plus(VALUE self, VALUE other)
     switch (TYPE(other)) {
       case T_FIXNUM:
 	{
-	    long jd;
+	    int jd;
 
 	    get_d_jd(dat);
 
-	    jd = dat->l.jd + FIX2LONG(other);
+	    jd = dat->l.jd + FIX2INT(other);
 
 	    if (LIGHTABLE_JD(jd) && jd >= dat->l.sg)
 		return d_lite_s_new_internal(CLASS_OF(self),
@@ -1936,7 +1936,7 @@ d_lite_plus(VALUE self, VALUE other)
       case T_FLOAT:
 	{
 	    double d = NUM2DBL(other);
-	    long l = round(d);
+	    int l = round(d);
 	    if (l == d && LIGHTABLE_JD(l))
 		return d_lite_plus(self, INT2FIX(l));
 	}
@@ -1952,7 +1952,7 @@ minus_dd(VALUE self, VALUE other)
 
     if (light_mode_p(adat) &&
 	light_mode_p(bdat)) {
-	long d, sf;
+	int d, sf;
 	int df;
 	VALUE r;
 
@@ -1980,7 +1980,7 @@ minus_dd(VALUE self, VALUE other)
 	    df += 1;
 	    sf -= SECOND_IN_NANOSECONDS;
 	}
-	r = rb_rational_new1(LONG2NUM(d));
+	r = rb_rational_new1(INT2NUM(d));
 	if (df)
 	    r = f_add(r, rb_rational_new2(INT2FIX(df),
 					  INT2FIX(DAY_IN_SECONDS)));
@@ -2017,13 +2017,13 @@ d_lite_minus(VALUE self, VALUE other)
 
 	if (light_mode_p(adat) &&
 	    light_mode_p(bdat)) {
-	    long d;
+	    int d;
 
 	    get_d_jd(adat);
 	    get_d_jd(bdat);
 
 	    d = adat->l.jd - bdat->l.jd;
-	    return rb_rational_new1(LONG2NUM(d));
+	    return rb_rational_new1(INT2NUM(d));
 	}
     }
 
@@ -2397,7 +2397,7 @@ d_lite_set_vtm_and_timev(VALUE self, struct vtm *vtm, VALUE *timev)
 	get_d_jd(dat);
 	get_d_civil(dat);
 
-	vtm->year = LONG2NUM(dat->l.year);
+	vtm->year = INT2NUM(dat->l.year);
 	vtm->mon = dat->l.mon;
 	vtm->mday = dat->l.mday;
 	vtm->hour = 0;
@@ -2423,7 +2423,7 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
     {
 	VALUE vfmt;
 	const char *fmt;
-	long len;
+	int len;
 	char buffer[SMALLBUF], *buf = buffer;
 	struct vtm vtm;
 	VALUE timev;
@@ -2501,7 +2501,7 @@ d_lite_marshal_dump(VALUE self)
 	a = rb_ary_new3(3, dat->r.ajd, dat->r.of, dat->r.sg);
     else {
 	get_d_jd(dat);
-	a = rb_assoc_new(LONG2NUM(dat->l.jd), DBL2NUM(dat->l.sg));
+	a = rb_assoc_new(INT2NUM(dat->l.jd), DBL2NUM(dat->l.sg));
     }
 
     if (FL_TEST(self, FL_EXIVAR)) {
@@ -2535,7 +2535,7 @@ d_lite_marshal_load(VALUE self, VALUE a)
 	dat->r.flags = 0;
 	break;
       case 2:
-	dat->l.jd = NUM2LONG(RARRAY_PTR(a)[0]);
+	dat->l.jd = NUM2INT(RARRAY_PTR(a)[0]);
 	dat->l.sg = NUM2DBL(RARRAY_PTR(a)[1]);
 	dat->l.year = 0;
 	dat->l.mon = 0;
@@ -2567,8 +2567,8 @@ d_right_cache(VALUE self)
 /* datetime light */
 
 inline static VALUE
-dt_lite_s_new_internal(VALUE klass, long jd, int df,
-		       long sf, int of, double sg,
+dt_lite_s_new_internal(VALUE klass, int jd, int df,
+		       int sf, int of, double sg,
 		       int y, int m, int d,
 		       int h, int min, int s,
 		       unsigned flags)
@@ -2595,8 +2595,8 @@ dt_lite_s_new_internal(VALUE klass, long jd, int df,
 }
 
 static VALUE
-dt_lite_s_new_internal_wo_civil(VALUE klass, long jd, int df,
-				long sf, int of, double sg,
+dt_lite_s_new_internal_wo_civil(VALUE klass, int jd, int df,
+				int sf, int of, double sg,
 				unsigned flags)
 {
     return dt_lite_s_new_internal(klass, jd, df, sf, of, sg,
@@ -2613,7 +2613,7 @@ static VALUE
 dt_lite_s_new_l_bang(int argc, VALUE *argv, VALUE klass)
 {
     VALUE vjd, vdf, vsf, vof, vsg;
-    long jd;
+    int jd;
 
     rb_scan_args(argc, argv, "05", &vjd, &vdf, &vsf, &vof, &vsg);
 
@@ -2633,7 +2633,7 @@ dt_lite_s_new_l_bang(int argc, VALUE *argv, VALUE klass)
 	!FIXNUM_P(vsf) ||
 	!FIXNUM_P(vof))
 	rb_raise(rb_eArgError, "cannot create");
-    jd = NUM2LONG(vjd);
+    jd = NUM2INT(vjd);
     if (!LIGHTABLE_JD(jd))
 	rb_raise(rb_eArgError, "cannot create");
 
@@ -2674,7 +2674,7 @@ static VALUE
 datetime_s_jd(int argc, VALUE *argv, VALUE klass)
 {
     VALUE vjd, vh, vmin, vs, vof, vsg;
-    long jd;
+    int jd;
     int h, min, s, rh, rmin, rs, rof;
     double sg;
 
@@ -2703,7 +2703,7 @@ datetime_s_jd(int argc, VALUE *argv, VALUE klass)
       case 2:
 	h = NUM2INT(vh);
       case 1:
-	jd = NUM2LONG(vjd);
+	jd = NUM2INT(vjd);
 	if (!LIGHTABLE_JD(jd))
 	    return cforwardv("jd_r");
     }
@@ -2788,7 +2788,7 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
     }
 
     {
-	long jd;
+	int jd;
 	int ns;
 
 	if (!valid_ordinal_p(y, d, sg, &rd, &jd, &ns))
@@ -2890,7 +2890,7 @@ datetime_s_civil(int argc, VALUE *argv, VALUE klass)
 				      LIGHT_MODE | HAVE_CIVIL | HAVE_TIME);
     }
     else {
-	long jd;
+	int jd;
 	int ns;
 
 	if (!valid_civil_p(y, m, d, sg, &rm, &rd, &jd, &ns))
@@ -2983,7 +2983,7 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
     }
 
     {
-	long jd;
+	int jd;
 	int ns;
 
 	if (!valid_commercial_p(y, w, d, sg, &rw, &rd, &jd, &ns))
@@ -3024,7 +3024,7 @@ datetime_s_now(int argc, VALUE *argv, VALUE klass)
 #endif
     time_t sec;
     struct tm tm;
-    long y, sf;
+    int y, sf;
     int m, d, h, min, s, of;
 
     rb_scan_args(argc, argv, "01", &vsg);
@@ -3059,9 +3059,9 @@ datetime_s_now(int argc, VALUE *argv, VALUE klass)
     of = (int)-timezone;
 #endif
 #ifdef HAVE_CLOCK_GETTIME
-    sf = ts.tv_nsec;
+    sf = (int)ts.tv_nsec;
 #else
-    sf = tv.tv_usec * 1000;
+    sf = (int)tv.tv_usec * 1000;
 #endif
 
     if (!LIGHTABLE_YEAR(y))
@@ -3069,20 +3069,20 @@ datetime_s_now(int argc, VALUE *argv, VALUE klass)
 
     if (isinf(sg) && sg < 0)
 	return dt_lite_s_new_internal(klass, 0, 0, sf, of, sg,
-				      (int)y, m, d, h, min, s,
+				      y, m, d, h, min, s,
 				      LIGHT_MODE | HAVE_CIVIL | HAVE_TIME);
     else {
-	long jd;
+	int jd;
 	int ns;
 
-	civil_to_jd((int)y, m, d, sg, &jd, &ns);
+	civil_to_jd(y, m, d, sg, &jd, &ns);
 
 	return dt_lite_s_new_internal(klass,
 				      jd_local_to_utc(jd,
 						      time_to_df(h, min, s),
 						      of),
 				      0, sf, of, sg,
-				      (int)y, m, d, h, min, s,
+				      y, m, d, h, min, s,
 				      LIGHT_MODE | HAVE_JD |
 				      HAVE_CIVIL | HAVE_TIME);
     }
@@ -3133,7 +3133,7 @@ dt_lite_amjd(VALUE self)
 
 	get_dt_jd(dat);
 	get_dt_df(dat);
-	r = rb_rational_new1(LONG2NUM(dat->l.jd - 2400001L));
+	r = rb_rational_new1(INT2NUM(dat->l.jd - 2400001));
 	if (dat->l.df)
 	    r = f_add(r, rb_rational_new2(INT2FIX(dat->l.df),
 					  INT2FIX(DAY_IN_SECONDS)));
@@ -3178,7 +3178,7 @@ dt_lite_mjd(VALUE self)
     {
 	get_dt_jd(dat);
 	get_dt_df(dat);
-	return LONG2NUM(local_jd(dat) - 2400001L);
+	return INT2NUM(local_jd(dat) - 2400001);
     }
 }
 
@@ -3197,7 +3197,7 @@ dt_lite_ld(VALUE self)
     {
 	get_dt_jd(dat);
 	get_dt_df(dat);
-	return LONG2NUM(local_jd(dat) - 2299160L);
+	return INT2NUM(local_jd(dat) - 2299160);
     }
 }
 
@@ -3706,13 +3706,13 @@ dt_lite_plus(VALUE self, VALUE other)
     switch (TYPE(other)) {
       case T_FIXNUM:
 	{
-	    long jd;
+	    int jd;
 
 	    get_dt1(self);
 	    get_dt_jd(dat);
 	    get_dt_df(dat);
 
-	    jd = dat->l.jd + FIX2LONG(other);
+	    jd = dat->l.jd + FIX2INT(other);
 
 	    if (LIGHTABLE_JD(jd) && jd >= dat->l.sg)
 		return dt_lite_s_new_internal(CLASS_OF(self),
@@ -3730,7 +3730,7 @@ dt_lite_plus(VALUE self, VALUE other)
 	break;
       case T_FLOAT:
 	{
-	    long sf;
+	    int sf;
 	    double jd, o, tmp;
 	    int s, df;
 
@@ -3751,9 +3751,9 @@ dt_lite_plus(VALUE self, VALUE other)
 	    o = modf(o, &jd);
 	    o *= DAY_IN_SECONDS;
 	    o = modf(o, &tmp);
-	    df = (int)tmp;
+	    df = tmp;
 	    o *= SECOND_IN_NANOSECONDS;
-	    sf = (long)round(o);
+	    sf = round(o);
 
 	    if (s < 0) {
 		jd = -jd;
@@ -3785,7 +3785,7 @@ dt_lite_plus(VALUE self, VALUE other)
 
 	    if (LIGHTABLE_JD(jd) && jd >= dat->l.sg)
 		return dt_lite_s_new_internal(CLASS_OF(self),
-					      (long)jd,
+					      jd,
 					      df,
 					      sf,
 					      dat->l.of,
@@ -3993,13 +3993,13 @@ dt_lite_set_vtm_and_timev(VALUE self, struct vtm *vtm, VALUE *timev)
 	get_dt_civil(dat);
 	get_dt_time(dat);
 
-	vtm->year = LONG2NUM(dat->l.year);
+	vtm->year = INT2NUM(dat->l.year);
 	vtm->mon = dat->l.mon;
 	vtm->mday = dat->l.mday;
 	vtm->hour = dat->l.hour;
 	vtm->min = dat->l.min;
 	vtm->sec = dat->l.sec;
-	vtm->subsecx = LONG2NUM(dat->l.sf);
+	vtm->subsecx = INT2NUM(dat->l.sf);
 	vtm->utc_offset = INT2FIX(dat->l.of);
 	vtm->wday = jd_to_wday(local_jd(dat));
 	vtm->yday = civil_to_yday(dat->l.year, dat->l.mon, dat->l.mday);
@@ -4043,7 +4043,7 @@ dt_lite_marshal_dump(VALUE self)
 	get_dt_jd(dat);
 	get_dt_df(dat);
 	a = rb_ary_new3(5,
-			LONG2NUM(dat->l.jd), INT2FIX(dat->l.df),
+			INT2NUM(dat->l.jd), INT2FIX(dat->l.df),
 			INT2FIX(dat->l.sf),
 			INT2FIX(dat->l.of), DBL2NUM(dat->l.sg));
     }
@@ -4079,7 +4079,7 @@ dt_lite_marshal_load(VALUE self, VALUE a)
 	dat->r.flags = 0;
 	break;
       case 5:
-	dat->l.jd = NUM2LONG(RARRAY_PTR(a)[0]);
+	dat->l.jd = NUM2INT(RARRAY_PTR(a)[0]);
 	dat->l.df = FIX2INT(RARRAY_PTR(a)[1]);
 	dat->l.sf = FIX2INT(RARRAY_PTR(a)[2]);
 	dat->l.of = FIX2INT(RARRAY_PTR(a)[3]);
@@ -4116,14 +4116,14 @@ dt_right_cache(VALUE self)
 
 #ifndef NDEBUG
 static int
-test_civil(long from, long to, double sg)
+test_civil(int from, int to, double sg)
 {
-    long j;
+    int j;
 
     fprintf(stderr, "%ld...%ld (%ld) - %.0f\n", from, to, to - from, sg);
     for (j = from; j <= to; j++) {
 	int y, m, d, ns;
-	long rj;
+	int rj;
 
 	jd_to_civil(j, sg, &y, &m, &d);
 	civil_to_jd(y, m, d, sg, &rj, &ns);
@@ -4158,14 +4158,14 @@ date_s_test_civil(VALUE klass)
 }
 
 static int
-test_ordinal(long from, long to, double sg)
+test_ordinal(int from, int to, double sg)
 {
-    long j;
+    int j;
 
     fprintf(stderr, "%ld...%ld (%ld) - %.0f\n", from, to, to - from, sg);
     for (j = from; j <= to; j++) {
 	int y, d, ns;
-	long rj;
+	int rj;
 
 	jd_to_ordinal(j, sg, &y, &d);
 	ordinal_to_jd(y, d, sg, &rj, &ns);
@@ -4200,14 +4200,14 @@ date_s_test_ordinal(VALUE klass)
 }
 
 static int
-test_commercial(long from, long to, double sg)
+test_commercial(int from, int to, double sg)
 {
-    long j;
+    int j;
 
     fprintf(stderr, "%ld...%ld (%ld) - %.0f\n", from, to, to - from, sg);
     for (j = from; j <= to; j++) {
 	int y, w, d, ns;
-	long rj;
+	int rj;
 
 	jd_to_commercial(j, sg, &y, &w, &d);
 	commercial_to_jd(y, w, d, sg, &rj, &ns);
@@ -4242,14 +4242,14 @@ date_s_test_commercial(VALUE klass)
 }
 
 static int
-test_weeknum(long from, long to, int f, double sg)
+test_weeknum(int from, int to, int f, double sg)
 {
-    long j;
+    int j;
 
     fprintf(stderr, "%ld...%ld (%ld) - %.0f\n", from, to, to - from, sg);
     for (j = from; j <= to; j++) {
 	int y, w, d, ns;
-	long rj;
+	int rj;
 
 	jd_to_weeknum(j, f, sg, &y, &w, &d);
 	weeknum_to_jd(y, w, d, f, sg, &rj, &ns);
@@ -4288,14 +4288,14 @@ date_s_test_weeknum(VALUE klass)
 
 
 static int
-test_nth_kday(long from, long to, double sg)
+test_nth_kday(int from, int to, double sg)
 {
-    long j;
+    int j;
 
     fprintf(stderr, "%ld...%ld (%ld) - %.0f\n", from, to, to - from, sg);
     for (j = from; j <= to; j++) {
 	int y, m, n, k, ns;
-	long rj;
+	int rj;
 
 	jd_to_nth_kday(j, sg, &y, &m, &n, &k);
 	nth_kday_to_jd(y, m, n, k, sg, &rj, &ns);
diff --git a/ext/date/date_strftime.c b/ext/date/date_strftime.c
index 4774137..1cfa086 100644
--- a/ext/date/date_strftime.c
+++ b/ext/date/date_strftime.c
@@ -175,10 +175,10 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
 	char *start = s;
 	const char *sp, *tp;
 	auto char tbuf[100];
-	long off;
+	int off;
 	ptrdiff_t i;
 	int w;
-	long y;
+	int y;
 	int precision, flags, colons;
 	char padding;
 	enum {LEFT, CHCASE, LOWER, UPPER, LOCALE_O, LOCALE_E};
@@ -475,8 +475,8 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
 		case 'Y':	/* year with century */
 			SKIP_MODIFIER_O;
                         if (FIXNUM_P(vtm->year)) {
-                            long y = FIX2LONG(vtm->year);
-                            FMT('0', 0 <= y ? 4 : 5, "ld", y);
+                            long ly = FIX2LONG(vtm->year);
+                            FMT('0', 0 <= ly ? 4 : 5, "ld", ly);
                         }
                         else {
                             FMTV('0', 4, "d", vtm->year);
@@ -490,7 +490,7 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
 				long aoff;
 				int hl, hw;
 
-				off = NUM2LONG(rb_funcall(vtm->utc_offset, rb_intern("round"), 0));
+				off = NUM2INT(rb_funcall(vtm->utc_offset, rb_intern("round"), 0));
 
 				aoff = off;
 				if (aoff < 0)
@@ -699,6 +699,7 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
 			 */
 			SKIP_MODIFIER_EO;
                         {
+                                long ly;
                                 VALUE yv = vtm->year;
                                 w = iso8601wknum_v(vtm);
                                 if (vtm->mon == 12 && w == 1)
@@ -708,8 +709,8 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
 
                                 if (*format == 'G') {
                                         if (FIXNUM_P(yv)) {
-                                                long y = FIX2LONG(yv);
-                                                FMT('0', 0 <= y ? 4 : 5, "ld", y);
+                                                ly = FIX2LONG(yv);
+                                                FMT('0', 0 <= ly ? 4 : 5, "ld", ly);
                                         }
                                         else {
                                                 FMTV('0', 4, "d", yv);
@@ -717,8 +718,8 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
                                 }
                                 else {
                                         yv = mod(yv, INT2FIX(100));
-                                        y = FIX2LONG(yv);
-                                        FMT('0', 2, "ld", y);
+                                        ly = FIX2LONG(yv);
+                                        FMT('0', 2, "ld", ly);
                                 }
                                 continue;
                         }
@@ -751,7 +752,7 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
 			{
                                 VALUE subsec = mod(timev, INT2FIX(1));
                                 int ww;
-                                long n;
+                                int n;
 
                                 ww = precision;
                                 while (9 <= ww) {
@@ -878,10 +879,10 @@ date_strftime(char *s, size_t maxsize, const char *format, const struct vtm *vtm
 #ifndef __STDC__
 static int
 isleap(year)
-long year;
+int year;
 #else
 static int
-isleap(long year)
+isleap(int year)
 #endif
 {
 	return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
@@ -905,7 +906,7 @@ vtm2tm_noyear(const struct vtm *vtm, struct tm *result)
     tm.tm_yday = vtm->yday-1;
     tm.tm_isdst = vtm->isdst;
 #if defined(HAVE_STRUCT_TM_TM_GMTOFF)
-    tm.tm_gmtoff = NUM2LONG(vtm->utc_offset);
+    tm.tm_gmtoff = NUM2INT(vtm->utc_offset);
 #endif
 #if defined(HAVE_TM_ZONE)
     tm.tm_zone = (char *)vtm->zone;


-- 
http://redmine.ruby-lang.org