[前][次][番号順一覧][スレッド一覧]

ruby-changes:29963

From: usa <ko1@a...>
Date: Wed, 17 Jul 2013 10:10:28 +0900 (JST)
Subject: [ruby-changes:29963] usa:r42015 (ruby_1_9_3): merge revision(s) 41077,41105: [Backport #8578]

usa	2013-07-17 10:10:14 +0900 (Wed, 17 Jul 2013)

  New Revision: 42015

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42015

  Log:
    merge revision(s) 41077,41105: [Backport #8578]
    
    * ext/date/date_core.c: fixed a bug [ruby-core:55295].  reported
      by Riley Lynch.
    
    * ext/date/date_core.c: fixed coding error [ruby-core:55337].
      reported by Riley Lynch.

  Modified directories:
    branches/ruby_1_9_3/
  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/ext/date/date_core.c
    branches/ruby_1_9_3/test/date/test_switch_hitter.rb
    branches/ruby_1_9_3/version.h

Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 42014)
+++ ruby_1_9_3/ChangeLog	(revision 42015)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ChangeLog#L1
+Wed Jul 17 09:59:33 2013  Tadayoshi Funaba  <tadf@d...>
+
+	* ext/date/date_core.c: fixed coding error [ruby-core:55337].
+	  reported by Riley Lynch.
+
+Wed Jul 17 09:59:33 2013  Tadayoshi Funaba  <tadf@d...>
+
+	* ext/date/date_core.c: fixed a bug [ruby-core:55295].  reported
+	  by Riley Lynch.
+
 Thu Jul 11 10:07:15 2013  Kenta Murata  <mrkn@m...>
 
 	* ext/bigdecimal/bigdecimal.c (BigMath_s_exp): Fix for the cases when
Index: ruby_1_9_3/ext/date/date_core.c
===================================================================
--- ruby_1_9_3/ext/date/date_core.c	(revision 42014)
+++ ruby_1_9_3/ext/date/date_core.c	(revision 42015)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L1
 /*
-  date_core.c: Coded by Tadayoshi Funaba 2010, 2011
+  date_core.c: Coded by Tadayoshi Funaba 2010-2013
 */
 
 #include "ruby.h"
@@ -1109,6 +1109,28 @@ m_virtual_sg(union DateData *x) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L1109
 	return c_virtual_sg(x);
 }
 
+#define canonicalize_jd(_nth, _jd) \
+{\
+    if (_jd < 0) {\
+	_nth = f_sub(_nth, INT2FIX(1));\
+	_jd += CM_PERIOD;\
+    }\
+    if (_jd >= CM_PERIOD) {\
+	_nth = f_add(_nth, INT2FIX(1));\
+	_jd -= CM_PERIOD;\
+    }\
+}
+
+inline static void
+canonicalize_s_jd(union DateData *x)
+{
+    int j = x->s.jd;
+    assert(have_jd_p(x));
+    canonicalize_jd(x->s.nth, x->s.jd);
+    if (x->s.jd != j)
+	x->flags &= ~HAVE_CIVIL;
+}
+
 inline static void
 get_s_jd(union DateData *x)
 {
@@ -1194,6 +1216,16 @@ get_c_time(union DateData *x) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L1216
 }
 
 inline static void
+canonicalize_c_jd(union DateData *x)
+{
+    int j = x->c.jd;
+    assert(have_jd_p(x));
+    canonicalize_jd(x->c.nth, x->c.jd);
+    if (x->c.jd != j)
+	x->flags &= ~HAVE_CIVIL;
+}
+
+inline static void
 get_c_jd(union DateData *x)
 {
     assert(complex_dat_p(x));
@@ -1366,6 +1398,19 @@ guess_style(VALUE y, double sg) /* -/+oo https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L1398
     return style;
 }
 
+inline static void
+m_canonicalize_jd(union DateData *x)
+{
+    if (simple_dat_p(x)) {
+	get_s_jd(x);
+	canonicalize_s_jd(x);
+    }
+    else {
+	get_c_jd(x);
+	canonicalize_c_jd(x);
+    }
+}
+
 inline static VALUE
 m_nth(union DateData *x)
 {
@@ -1972,7 +2017,7 @@ civil_to_jd(VALUE y, int m, int d, doubl https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L2017
 	    *ry = FIX2INT(y);
 	else {
 	    VALUE nth2;
-	    decode_year(y, ns ? -1 : +1, &nth2, ry);
+	    decode_year(y, *ns ? -1 : +1, &nth2, ry);
 	}
     }
     else {
@@ -2007,7 +2052,7 @@ ordinal_to_jd(VALUE y, int d, double sg, https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L2052
 	    *ry = FIX2INT(y);
 	else {
 	    VALUE nth2;
-	    decode_year(y, ns ? -1 : +1, &nth2, ry);
+	    decode_year(y, *ns ? -1 : +1, &nth2, ry);
 	}
     }
     else {
@@ -2042,7 +2087,7 @@ commercial_to_jd(VALUE y, int w, int d, https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L2087
 	    *ry = FIX2INT(y);
 	else {
 	    VALUE nth2;
-	    decode_year(y, ns ? -1 : +1, &nth2, ry);
+	    decode_year(y, *ns ? -1 : +1, &nth2, ry);
 	}
     }
     else {
@@ -2077,7 +2122,7 @@ weeknum_to_jd(VALUE y, int w, int d, int https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L2122
 	    *ry = FIX2INT(y);
 	else {
 	    VALUE nth2;
-	    decode_year(y, ns ? -1 : +1, &nth2, ry);
+	    decode_year(y, *ns ? -1 : +1, &nth2, ry);
 	}
     }
     else {
@@ -2112,7 +2157,7 @@ nth_kday_to_jd(VALUE y, int m, int n, in https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L2157
 	    *ry = FIX2INT(y);
 	else {
 	    VALUE nth2;
-	    decode_year(y, ns ? -1 : +1, &nth2, ry);
+	    decode_year(y, *ns ? -1 : +1, &nth2, ry);
 	}
     }
     else {
@@ -2151,7 +2196,7 @@ valid_ordinal_p(VALUE y, int d, double s https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L2196
 	    *ry = FIX2INT(y);
 	else {
 	    VALUE nth2;
-	    decode_year(y, ns ? -1 : +1, &nth2, ry);
+	    decode_year(y, *ns ? -1 : +1, &nth2, ry);
 	}
     }
     else {
@@ -2190,7 +2235,7 @@ valid_civil_p(VALUE y, int m, int d, dou https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L2235
 	    *ry = FIX2INT(y);
 	else {
 	    VALUE nth2;
-	    decode_year(y, ns ? -1 : +1, &nth2, ry);
+	    decode_year(y, *ns ? -1 : +1, &nth2, ry);
 	}
     }
     else {
@@ -2226,7 +2271,7 @@ valid_commercial_p(VALUE y, int w, int d https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L2271
 	    *ry = FIX2INT(y);
 	else {
 	    VALUE nth2;
-	    decode_year(y, ns ? -1 : +1, &nth2, ry);
+	    decode_year(y, *ns ? -1 : +1, &nth2, ry);
 	}
     }
     else {
@@ -2256,7 +2301,7 @@ valid_weeknum_p(VALUE y, int w, int d, i https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L2301
 	    *ry = FIX2INT(y);
 	else {
 	    VALUE nth2;
-	    decode_year(y, ns ? -1 : +1, &nth2, ry);
+	    decode_year(y, *ns ? -1 : +1, &nth2, ry);
 	}
     }
     else {
@@ -2287,7 +2332,7 @@ valid_nth_kday_p(VALUE y, int m, int n, https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L2332
 	    *ry = FIX2INT(y);
 	else {
 	    VALUE nth2;
-	    decode_year(y, ns ? -1 : +1, &nth2, ry);
+	    decode_year(y, *ns ? -1 : +1, &nth2, ry);
 	}
     }
     else {
@@ -5569,15 +5614,7 @@ d_lite_plus(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L5614
 		jd = m_jd(dat);
 	    else {
 		jd = m_jd(dat) + (int)t;
-
-		if (jd < 0) {
-		    nth = f_sub(nth, INT2FIX(1));
-		    jd += CM_PERIOD;
-		}
-		else if (jd >= CM_PERIOD) {
-		    nth = f_add(nth, INT2FIX(1));
-		    jd -= CM_PERIOD;
-		}
+		canonicalize_jd(nth, jd);
 	    }
 
 	    if (simple_dat_p(dat))
@@ -5630,14 +5667,7 @@ d_lite_plus(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L5667
 		jd = m_jd(dat);
 	    else {
 		jd = m_jd(dat) + jd;
-		if (jd < 0) {
-		    nth = f_sub(nth, INT2FIX(1));
-		    jd += CM_PERIOD;
-		}
-		else if (jd >= CM_PERIOD) {
-		    nth = f_add(nth, INT2FIX(1));
-		    jd -= CM_PERIOD;
-		}
+		canonicalize_jd(nth, jd);
 	    }
 
 	    if (f_zero_p(nth))
@@ -5744,14 +5774,7 @@ d_lite_plus(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L5774
 		jd = m_jd(dat);
 	    else {
 		jd = m_jd(dat) + jd;
-		if (jd < 0) {
-		    nth = f_sub(nth, INT2FIX(1));
-		    jd += CM_PERIOD;
-		}
-		else if (jd >= CM_PERIOD) {
-		    nth = f_add(nth, INT2FIX(1));
-		    jd -= CM_PERIOD;
-		}
+		canonicalize_jd(nth, jd);
 	    }
 
 	    if (f_zero_p(nth))
@@ -5854,14 +5877,7 @@ d_lite_plus(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L5877
 		jd = m_jd(dat);
 	    else {
 		jd = m_jd(dat) + jd;
-		if (jd < 0) {
-		    nth = f_sub(nth, INT2FIX(1));
-		    jd += CM_PERIOD;
-		}
-		else if (jd >= CM_PERIOD) {
-		    nth = f_add(nth, INT2FIX(1));
-		    jd -= CM_PERIOD;
-		}
+		canonicalize_jd(nth, jd);
 	    }
 
 	    if (f_zero_p(nth))
@@ -5905,15 +5921,7 @@ minus_dd(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L5921
 	d = m_jd(adat) - m_jd(bdat);
 	df = m_df(adat) - m_df(bdat);
 	sf = f_sub(m_sf(adat), m_sf(bdat));
-
-	if (d < 0) {
-	    n = f_sub(n, INT2FIX(1));
-	    d += CM_PERIOD;
-	}
-	else if (d >= CM_PERIOD) {
-	    n = f_add(n, INT2FIX(1));
-	    d -= CM_PERIOD;
-	}
+	canonicalize_jd(n, d);
 
 	if (df < 0) {
 	    d -= 1;
@@ -6299,6 +6307,8 @@ cmp_dd(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L6307
 	int a_jd, b_jd,
 	    a_df, b_df;
 
+	m_canonicalize_jd(adat);
+	m_canonicalize_jd(bdat);
 	a_nth = m_nth(adat);
 	b_nth = m_nth(bdat);
 	if (f_eqeq_p(a_nth, b_nth)) {
@@ -6379,6 +6389,8 @@ d_lite_cmp(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L6389
 	    VALUE a_nth, b_nth;
 	    int a_jd, b_jd;
 
+	    m_canonicalize_jd(adat);
+	    m_canonicalize_jd(bdat);
 	    a_nth = m_nth(adat);
 	    b_nth = m_nth(bdat);
 	    if (f_eqeq_p(a_nth, b_nth)) {
@@ -6413,6 +6425,8 @@ d_lite_cmp(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L6425
 		a_pd, b_pd;
 #endif
 
+	    m_canonicalize_jd(adat);
+	    m_canonicalize_jd(bdat);
 	    a_nth = m_nth(adat);
 	    b_nth = m_nth(bdat);
 	    if (f_eqeq_p(a_nth, b_nth)) {
@@ -6520,6 +6534,8 @@ d_lite_equal(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L6534
 	    VALUE a_nth, b_nth;
 	    int a_jd, b_jd;
 
+	    m_canonicalize_jd(adat);
+	    m_canonicalize_jd(bdat);
 	    a_nth = m_nth(adat);
 	    b_nth = m_nth(bdat);
 	    a_jd = m_local_jd(adat);
@@ -6541,6 +6557,8 @@ d_lite_equal(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/date/date_core.c#L6557
 		a_pd, b_pd;
 #endif
 
+	    m_canonicalize_jd(adat);
+	    m_canonicalize_jd(bdat);
 	    a_nth = m_nth(adat);
 	    b_nth = m_nth(bdat);
 	    if (f_eqeq_p(a_nth, b_nth)) {
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 42014)
+++ ruby_1_9_3/version.h	(revision 42015)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/version.h#L1
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 452
+#define RUBY_PATCHLEVEL 453
 
-#define RUBY_RELEASE_DATE "2013-07-11"
+#define RUBY_RELEASE_DATE "2013-07-17"
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 7
-#define RUBY_RELEASE_DAY 11
+#define RUBY_RELEASE_DAY 17
 
 #include "ruby/version.h"
 
Index: ruby_1_9_3/test/date/test_switch_hitter.rb
===================================================================
--- ruby_1_9_3/test/date/test_switch_hitter.rb	(revision 42014)
+++ ruby_1_9_3/test/date/test_switch_hitter.rb	(revision 42015)
@@ -472,6 +472,59 @@ class TestSH < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/test/date/test_switch_hitter.rb#L472
     period2_iter(+cm_period * (1 << 64) - 3, +cm_period * (1 << 64) + 3)
   end
 
+  def test_different_alignments
+    assert_equal(0, Date.jd(0) <=> Date.civil(-4713, 11, 24, Date::GREGORIAN))
+    assert_equal(0, Date.jd(213447717) <=> Date.civil(579687, 11, 24))
+    assert_equal(0, Date.jd(-213447717) <=> Date.civil(-589113, 11, 24, Date::GREGORIAN))
+
+    assert_equal(0, Date.jd(0) <=> DateTime.civil(-4713, 11, 24, 0, 0, 0, 0, Date::GREGORIAN))
+    assert_equal(0, Date.jd(213447717) <=> DateTime.civil(579687, 11, 24))
+    assert_equal(0, Date.jd(-213447717) <=> DateTime.civil(-589113, 11, 24, 0, 0, 0, 0, Date::GREGORIAN))
+
+    assert(Date.jd(0) == Date.civil(-4713, 11, 24, Date::GREGORIAN))
+    assert(Date.jd(213447717) == Date.civil(579687, 11, 24))
+    assert(Date.jd(-213447717) == Date.civil(-589113, 11, 24, Date::GREGORIAN))
+
+    assert(Date.jd(0) == DateTime.civil(-4713, 11, 24, 0, 0, 0, 0, Date::GREGORIAN))
+    assert(Date.jd(213447717) == DateTime.civil(579687, 11, 24))
+    assert(Date.jd(-213447717) == DateTime.civil(-589113, 11, 24, 0, 0, 0, 0, Date::GREGORIAN))
+
+    assert(Date.jd(0) === Date.civil(-4713, 11, 24, Date::GREGORIAN))
+    assert(Date.jd(213447717) === Date.civil(579687, 11, 24))
+    assert(Date.jd(-213447717) === Date.civil(-589113, 11, 24, Date::GREGORIAN))
+
+    assert(Date.jd(0) === DateTime.civil(-4713, 11, 24, 12, 0, 0, 0, Date::GREGORIAN))
+    assert(Date.jd(213447717) === DateTime.civil(579687, 11, 24, 12))
+    assert(Date.jd(-213447717) === DateTime.civil(-589113, 11, 24, 12, 0, 0, 0, Date::GREGORIAN))
+
+    a = Date.jd(0)
+    b = Date.civil(-4713, 11, 24, Date::GREGORIAN)
+    assert_equal(0, a <=> b)
+
+    a = Date.civil(-4712, 1, 1, Date::JULIAN)
+    b = Date.civil(-4713, 11, 24, Date::GREGORIAN)
+    a.jd; b.jd
+    assert_equal(0, a <=> b)
+
+    a = Date.jd(0)
+    b = Date.civil(-4713, 11, 24, Date::GREGORIAN)
+    assert(a == b)
+
+    a = Date.civil(-4712, 1, 1, Date::JULIAN)
+    b = Date.civil(-4713, 11, 24, Date::GREGORIAN)
+    a.jd; b.jd
+    assert(a == b)
+
+    a = Date.jd(0)
+    b = Date.civil(-4713, 11, 24, Date::GREGORIAN)
+    assert(a === b)
+
+    a = Date.civil(-4712, 1, 1, Date::JULIAN)
+    b = Date.civil(-4713, 11, 24, Date::GREGORIAN)
+    a.jd; b.jd
+    assert(a === b)
+  end
+
   def test_marshal
     s = "\x04\bU:\tDate[\bU:\rRational[\ai\x03\xCF\xD3Ji\ai\x00o:\x13Date::Infinity\x06:\a@di\xFA"
     d = Marshal.load(s)

Property changes on: ruby_1_9_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r41077,41105


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]