Project

General

Profile

Bug #6652 ยป 0001-compatible-marshal-loader.patch

nobu (Nobuyoshi Nakada), 06/27/2012 02:23 AM

View differences:

ext/date/date_core.c
7251 7251
		    INT2FIX(m_of(dat)),
7252 7252
		    DBL2NUM(m_sg(dat)));
7253 7253

  
7254
    if (FL_TEST(self, FL_EXIVAR)) {
7255
	rb_copy_generic_ivar(a, self);
7256
	FL_SET(a, FL_EXIVAR);
7257
    }
7258

  
7259 7254
    return a;
7260 7255
}
7261 7256

  
......
7336 7331
    return self;
7337 7332
}
7338 7333

  
7334
/* :nodoc: */
7335
static VALUE
7336
d_lite_old_load(VALUE klass, VALUE s)
7337
{
7338
    VALUE data = rb_marshal_load(s);
7339
    VALUE self = rb_obj_alloc(klass);
7340
    Check_Type(data, T_ARRAY);
7341
    if (RARRAY_LEN(data) == 2) {
7342
	const VALUE *ptr = RARRAY_PTR(data);
7343
	data = rb_ary_new3(3, ptr[0], INT2FIX(0), ptr[1]);
7344
    }
7345
    return d_lite_marshal_load(self, data);
7346
}
7339 7347

  
7340 7348
/* datetime */
7341 7349

  
......
9674 9682
#endif
9675 9683
    rb_define_method(cDate, "marshal_dump", d_lite_marshal_dump, 0);
9676 9684
    rb_define_method(cDate, "marshal_load", d_lite_marshal_load, 1);
9685
    rb_define_singleton_method(cDate, "_load", d_lite_old_load, 1);
9677 9686

  
9678 9687
    /* datetime */
9679 9688

  
test/date/test_date_marshal.rb
38 38
    assert_raise(RuntimeError){d.marshal_load(a)}
39 39
  end
40 40

  
41
  def test_marshal_old
42
    data = "\004\bu:\tDate=\004\b[\bo:\rRational\a:\017@numeratori\003%\275J:\021" \
43
           "@denominatori\ai\000i\003\031\025#"
44
    assert_equal(Date.new(1993, 2, 24), Marshal.load(data))
45

  
46
    data = "\004\bu:\rDateTimeC\004\b[\bo:\rRational\a:\017@numeratorl+\bK\355B\024\003\000:\021" \
47
           "@denominatori\002\030\025i\000i\003\031\025#"
48
    assert_equal(DateTime.new(1993, 2, 24, 12, 34, 56), Marshal.load(data))
49
  end
41 50
end
42
-