ruby-changes:29900
From: nagachika <ko1@a...>
Date: Sat, 13 Jul 2013 23:52:39 +0900 (JST)
Subject: [ruby-changes:29900] nagachika:r41952 (ruby_2_0_0): merge revision(s) 41077,41105: [Backport #8485] [Backport #8500] [Backport #8578]
nagachika 2013-07-13 23:52:27 +0900 (Sat, 13 Jul 2013) New Revision: 41952 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41952 Log: merge revision(s) 41077,41105: [Backport #8485] [Backport #8500] [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_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/ext/date/date_core.c branches/ruby_2_0_0/test/date/test_switch_hitter.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 41951) +++ ruby_2_0_0/ChangeLog (revision 41952) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Sat Jul 13 23:50:00 2013 Tadayoshi Funaba <tadf@d...> + + * ext/date/date_core.c: fixed coding error [ruby-core:55337]. + reported by Riley Lynch. + +Sat Jul 13 23:50:00 2013 Tadayoshi Funaba <tadf@d...> + + * ext/date/date_core.c: fixed a bug [ruby-core:55295]. reported + by Riley Lynch. + Sat Jul 13 23:41:25 2013 Tadayoshi Funaba <tadf@d...> * ext/date/date_parse.c (date_zone_to_diff): [ruby-core:55831]. Index: ruby_2_0_0/ext/date/date_core.c =================================================================== --- ruby_2_0_0/ext/date/date_core.c (revision 41951) +++ ruby_2_0_0/ext/date/date_core.c (revision 41952) @@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L1 /* - date_core.c: Coded by Tadayoshi Funaba 2010-2012 + date_core.c: Coded by Tadayoshi Funaba 2010-2013 */ #include "ruby.h" @@ -1104,6 +1104,28 @@ m_virtual_sg(union DateData *x) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L1104 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) { @@ -1189,6 +1211,16 @@ get_c_time(union DateData *x) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L1211 } 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)); @@ -1361,6 +1393,19 @@ guess_style(VALUE y, double sg) /* -/+oo https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L1393 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) { @@ -1967,7 +2012,7 @@ civil_to_jd(VALUE y, int m, int d, doubl https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L2012 *ry = FIX2INT(y); else { VALUE nth2; - decode_year(y, ns ? -1 : +1, &nth2, ry); + decode_year(y, *ns ? -1 : +1, &nth2, ry); } } else { @@ -2002,7 +2047,7 @@ ordinal_to_jd(VALUE y, int d, double sg, https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L2047 *ry = FIX2INT(y); else { VALUE nth2; - decode_year(y, ns ? -1 : +1, &nth2, ry); + decode_year(y, *ns ? -1 : +1, &nth2, ry); } } else { @@ -2037,7 +2082,7 @@ commercial_to_jd(VALUE y, int w, int d, https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L2082 *ry = FIX2INT(y); else { VALUE nth2; - decode_year(y, ns ? -1 : +1, &nth2, ry); + decode_year(y, *ns ? -1 : +1, &nth2, ry); } } else { @@ -2072,7 +2117,7 @@ weeknum_to_jd(VALUE y, int w, int d, int https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L2117 *ry = FIX2INT(y); else { VALUE nth2; - decode_year(y, ns ? -1 : +1, &nth2, ry); + decode_year(y, *ns ? -1 : +1, &nth2, ry); } } else { @@ -2107,7 +2152,7 @@ nth_kday_to_jd(VALUE y, int m, int n, in https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L2152 *ry = FIX2INT(y); else { VALUE nth2; - decode_year(y, ns ? -1 : +1, &nth2, ry); + decode_year(y, *ns ? -1 : +1, &nth2, ry); } } else { @@ -2146,7 +2191,7 @@ valid_ordinal_p(VALUE y, int d, double s https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L2191 *ry = FIX2INT(y); else { VALUE nth2; - decode_year(y, ns ? -1 : +1, &nth2, ry); + decode_year(y, *ns ? -1 : +1, &nth2, ry); } } else { @@ -2185,7 +2230,7 @@ valid_civil_p(VALUE y, int m, int d, dou https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L2230 *ry = FIX2INT(y); else { VALUE nth2; - decode_year(y, ns ? -1 : +1, &nth2, ry); + decode_year(y, *ns ? -1 : +1, &nth2, ry); } } else { @@ -2221,7 +2266,7 @@ valid_commercial_p(VALUE y, int w, int d https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L2266 *ry = FIX2INT(y); else { VALUE nth2; - decode_year(y, ns ? -1 : +1, &nth2, ry); + decode_year(y, *ns ? -1 : +1, &nth2, ry); } } else { @@ -2251,7 +2296,7 @@ valid_weeknum_p(VALUE y, int w, int d, i https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L2296 *ry = FIX2INT(y); else { VALUE nth2; - decode_year(y, ns ? -1 : +1, &nth2, ry); + decode_year(y, *ns ? -1 : +1, &nth2, ry); } } else { @@ -2282,7 +2327,7 @@ valid_nth_kday_p(VALUE y, int m, int n, https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L2327 *ry = FIX2INT(y); else { VALUE nth2; - decode_year(y, ns ? -1 : +1, &nth2, ry); + decode_year(y, *ns ? -1 : +1, &nth2, ry); } } else { @@ -5476,15 +5521,7 @@ d_lite_plus(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L5521 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)) @@ -5537,14 +5574,7 @@ d_lite_plus(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L5574 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)) @@ -5651,14 +5681,7 @@ d_lite_plus(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L5681 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)) @@ -5761,14 +5784,7 @@ d_lite_plus(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L5784 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)) @@ -5812,15 +5828,7 @@ minus_dd(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L5828 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; @@ -6198,6 +6206,8 @@ cmp_dd(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L6206 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)) { @@ -6276,6 +6286,8 @@ d_lite_cmp(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L6286 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)) { @@ -6310,6 +6322,8 @@ d_lite_cmp(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L6322 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)) { @@ -6415,6 +6429,8 @@ d_lite_equal(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L6429 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); @@ -6436,6 +6452,8 @@ d_lite_equal(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/date/date_core.c#L6452 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_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 41951) +++ ruby_2_0_0/version.h (revision 41952) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2013-07-13" -#define RUBY_PATCHLEVEL 265 +#define RUBY_PATCHLEVEL 266 #define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_MONTH 7 Index: ruby_2_0_0/test/date/test_switch_hitter.rb =================================================================== --- ruby_2_0_0/test/date/test_switch_hitter.rb (revision 41951) +++ ruby_2_0_0/test/date/test_switch_hitter.rb (revision 41952) @@ -474,6 +474,59 @@ class TestSH < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/date/test_switch_hitter.rb#L474 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_marshal14 s = "\x04\x03u:\x01\x04Date\x01\v\x04\x03[\x01\x02i\x03\xE8i%T" d = Marshal.load(s) Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r41077,41105 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/