Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
compatible marshal loader
* ext/date/date_core.c (d_lite_old_load): for compatibilities with
  1.8.  [ruby-core:45891] [Bug #6652]
  • Loading branch information
nobu committed Jun 27, 2012
commit c99f6285f2b50b949e3720efc519339053fa690b
19 changes: 14 additions & 5 deletions ext/date/date_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */

Expand Down
11 changes: 11 additions & 0 deletions test/date/test_date_marshal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,15 @@ def test_marshal
assert_raise(RuntimeError){d.marshal_load(a)}
end

def test_marshal_old
bug6652 = '[ruby-core:45891]'

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), bug6652)

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), bug6652)
end
end