From 89b118052312a8c2c3cdf214e18789c8d64d3ce0 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@ruby-lang.org>
Date: Wed, 27 Jun 2012 02:21:39 +0900
Subject: [PATCH] compatible marshal loader

* ext/date/date_core.c (d_lite_old_load): for compatibilities with
  1.8.
---
 ext/date/date_core.c           |   19 ++++++++++++++-----
 test/date/test_date_marshal.rb |    9 +++++++++
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index 82d078a..f5e117c 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -7251,11 +7251,6 @@ d_lite_marshal_dump(VALUE self)
 		    INT2FIX(m_of(dat)),
 		    DBL2NUM(m_sg(dat)));
 
-    if (FL_TEST(self, FL_EXIVAR)) {
-	rb_copy_generic_ivar(a, self);
-	FL_SET(a, FL_EXIVAR);
-    }
-
     return a;
 }
 
@@ -7336,6 +7331,19 @@ d_lite_marshal_load(VALUE self, VALUE a)
     return self;
 }
 
+/* :nodoc: */
+static VALUE
+d_lite_old_load(VALUE klass, VALUE s)
+{
+    VALUE data = rb_marshal_load(s);
+    VALUE self = rb_obj_alloc(klass);
+    Check_Type(data, T_ARRAY);
+    if (RARRAY_LEN(data) == 2) {
+	const VALUE *ptr = RARRAY_PTR(data);
+	data = rb_ary_new3(3, ptr[0], INT2FIX(0), ptr[1]);
+    }
+    return d_lite_marshal_load(self, data);
+}
 
 /* datetime */
 
@@ -9674,6 +9682,7 @@ Init_date_core(void)
 #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", d_lite_old_load, 1);
 
     /* datetime */
 
diff --git a/test/date/test_date_marshal.rb b/test/date/test_date_marshal.rb
index 4ea5565..a54163a 100644
--- a/test/date/test_date_marshal.rb
+++ b/test/date/test_date_marshal.rb
@@ -38,4 +38,13 @@ class TestDateMarshal < Test::Unit::TestCase
     assert_raise(RuntimeError){d.marshal_load(a)}
   end
 
+  def test_marshal_old
+    data = "\004\bu:\tDate=\004\b[\bo:\rRational\a:\017@numeratori\003%\275J:\021" \
+           "@denominatori\ai\000i\003\031\025#"
+    assert_equal(Date.new(1993, 2, 24), Marshal.load(data))
+
+    data = "\004\bu:\rDateTimeC\004\b[\bo:\rRational\a:\017@numeratorl+\bK\355B\024\003\000:\021" \
+           "@denominatori\002\030\025i\000i\003\031\025#"
+    assert_equal(DateTime.new(1993, 2, 24, 12, 34, 56), Marshal.load(data))
+  end
 end
-- 
1.7.10.2

