ruby-changes:24213
From: tadf <ko1@a...>
Date: Mon, 2 Jul 2012 05:37:52 +0900 (JST)
Subject: [ruby-changes:24213] tadf:r36264 (trunk): * ext/date/date_core.c (d_lite_marshal_load): accepts old dump.
tadf 2012-07-02 05:37:38 +0900 (Mon, 02 Jul 2012) New Revision: 36264 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36264 Log: * ext/date/date_core.c (d_lite_marshal_load): accepts old dump. Modified files: trunk/ChangeLog trunk/ext/date/date_core.c trunk/test/date/test_switch_hitter.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 36263) +++ ChangeLog (revision 36264) @@ -1,3 +1,7 @@ +Mon Jul 2 05:35:43 2012 Tadayoshi Funaba <tadf@d...> + + * ext/date/date_core.c (d_lite_marshal_load): accepts old dump. + Mon Jul 2 03:21:53 2012 Ayumu AIZAWA <ayumu.aizawa@g...> * README.EXT.ja: fixed args of have_struct_member() , Index: ext/date/date_core.c =================================================================== --- ext/date/date_core.c (revision 36263) +++ ext/date/date_core.c (revision 36264) @@ -7272,16 +7272,27 @@ rb_raise(rb_eTypeError, "expected an array"); switch (RARRAY_LEN(a)) { - case 3: + case 2: /* 1.6.x */ + case 3: /* 1.8.x, 1.9.2 */ { VALUE ajd, of, sg, nth, sf; int jd, df, rof; double rsg; - ajd = RARRAY_PTR(a)[0]; - of = RARRAY_PTR(a)[1]; - sg = RARRAY_PTR(a)[2]; + if (RARRAY_LEN(a) == 2) { + ajd = f_sub(RARRAY_PTR(a)[0], half_days_in_day); + of = INT2FIX(0); + sg = RARRAY_PTR(a)[1]; + if (!k_numeric_p(sg)) + sg = DBL2NUM(RTEST(sg) ? GREGORIAN : JULIAN); + } + else { + ajd = RARRAY_PTR(a)[0]; + of = RARRAY_PTR(a)[1]; + sg = RARRAY_PTR(a)[2]; + } + old_to_new(ajd, of, sg, &nth, &jd, &df, &sf, &rof, &rsg); @@ -7336,7 +7347,17 @@ return self; } +/* :nodoc: */ +static VALUE +date_s__load(VALUE klass, VALUE s) +{ + VALUE a, obj; + a = rb_marshal_load(s); + obj = d_lite_s_alloc(klass); + return d_lite_marshal_load(obj, a); +} + /* datetime */ /* @@ -9674,6 +9695,7 @@ #endif rb_define_method(cDate, "marshal_dump", d_lite_marshal_dump, 0); rb_define_method(cDate, "marshal_load", d_lite_marshal_load, 1); + rb_define_singleton_method(cDate, "_load", date_s__load, 1); /* datetime */ Index: test/date/test_switch_hitter.rb =================================================================== --- test/date/test_switch_hitter.rb (revision 36263) +++ test/date/test_switch_hitter.rb (revision 36264) @@ -472,7 +472,39 @@ period2_iter(+cm_period * (1 << 64) - 3, +cm_period * (1 << 64) + 3) end - def test_marshal +=begin + def test_marshal14 + s = "\x04\x03u:\x01\x04Date\x01\v\x04\x03[\x01\x02i\x03\xE8i%T" + d = Marshal.load(s) + assert_equal(Rational(4903887,2), d.ajd) + assert_equal(0, d.send(:offset)) + assert_equal(Date::GREGORIAN, d.start) + end + + def test_marshal16 + s = "\x04\x06u:\tDate\x0F\x04\x06[\ai\x03\xE8i%T" + d = Marshal.load(s) + assert_equal(Rational(4903887,2), d.ajd) + assert_equal(0, d.send(:offset)) + assert_equal(Date::GREGORIAN, d.start) + end + + def test_marshal18 + s = "\x04\bu:\tDateP\x04\b[\bo:\rRational\a:\x0F@numeratori\x03\xCF\xD3J:\x11@denominatori\ai\x00o:\x13Date::Infinity\x06:\a@di\xFA" + d = Marshal.load(s) + assert_equal(Rational(4903887,2), d.ajd) + assert_equal(0, d.send(:offset)) + assert_equal(Date::GREGORIAN, d.start) + + s = "\x04\bu:\rDateTime`\x04\b[\bo:\rRational\a:\x0F@numeratorl+\b\xC9\xB0\x81\xBD\x02\x00:\x11@denominatori\x02\xC0\x12o;\x00\a;\x06i\b;\ai\ro:\x13Date::Infinity\x06:\a@di\xFA" + d = Marshal.load(s) + assert_equal(Rational(11769327817,4800), d.ajd) + assert_equal(Rational(9,24), d.offset) + assert_equal(Date::GREGORIAN, d.start) + end +=end + + def test_marshal192 s = "\x04\bU:\tDate[\bU:\rRational[\ai\x03\xCF\xD3Ji\ai\x00o:\x13Date::Infinity\x06:\a@di\xFA" d = Marshal.load(s) assert_equal(Rational(4903887,2), d.ajd) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/