[前][次][番号順一覧][スレッド一覧]

ruby-changes:53482

From: nobu <ko1@a...>
Date: Tue, 13 Nov 2018 13:29:38 +0900 (JST)
Subject: [ruby-changes:53482] nobu:r65698 (trunk): date_core.c: respect COMPLEX_DAT bit

nobu	2018-11-13 13:29:31 +0900 (Tue, 13 Nov 2018)

  New Revision: 65698

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65698

  Log:
    date_core.c: respect COMPLEX_DAT bit
    
    * ext/date/date_core.c (d_lite_marshal_load): respect COMPLEX_DAT
      bit in the pre-allocated structure.

  Modified files:
    trunk/ext/date/date_core.c
    trunk/test/date/test_date_marshal.rb
Index: ext/date/date_core.c
===================================================================
--- ext/date/date_core.c	(revision 65697)
+++ ext/date/date_core.c	(revision 65698)
@@ -7121,6 +7121,10 @@ d_lite_marshal_dump(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L7121
 static VALUE
 d_lite_marshal_load(VALUE self, VALUE a)
 {
+    VALUE nth, sf;
+    int jd, df, of;
+    double sg;
+
     get_d1(self);
 
     rb_check_frozen(self);
@@ -7133,63 +7137,33 @@ d_lite_marshal_load(VALUE self, VALUE a) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L7137
       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;
-
+	    VALUE ajd, vof, vsg;
 
 	    if  (RARRAY_LEN(a) == 2) {
 		ajd = f_sub(RARRAY_AREF(a, 0), half_days_in_day);
-		of = INT2FIX(0);
-		sg = RARRAY_AREF(a, 1);
-		if (!k_numeric_p(sg))
-		    sg = DBL2NUM(RTEST(sg) ? GREGORIAN : JULIAN);
+		vof = INT2FIX(0);
+		vsg = RARRAY_AREF(a, 1);
+		if (!k_numeric_p(vsg))
+		    vsg = DBL2NUM(RTEST(vsg) ? GREGORIAN : JULIAN);
 	    }
 	    else {
 		ajd = RARRAY_AREF(a, 0);
-		of = RARRAY_AREF(a, 1);
-		sg = RARRAY_AREF(a, 2);
+		vof = RARRAY_AREF(a, 1);
+		vsg = RARRAY_AREF(a, 2);
 	    }
 
-	    old_to_new(ajd, of, sg,
-		       &nth, &jd, &df, &sf, &rof, &rsg);
-
-	    if (!df && f_zero_p(sf) && !rof) {
-		set_to_simple(self, &dat->s, nth, jd, rsg, 0, 0, 0, HAVE_JD);
-	    } else {
-		if (!complex_dat_p(dat))
-		    rb_raise(rb_eArgError,
-			     "cannot load complex into simple");
-
-		set_to_complex(self, &dat->c, nth, jd, df, sf, rof, rsg,
-			       0, 0, 0, 0, 0, 0,
-			       HAVE_JD | HAVE_DF);
-	    }
+	    old_to_new(ajd, vof, vsg,
+		       &nth, &jd, &df, &sf, &of, &sg);
 	}
 	break;
       case 6:
 	{
-	    VALUE nth, sf;
-	    int jd, df, of;
-	    double sg;
-
 	    nth = RARRAY_AREF(a, 0);
 	    jd = NUM2INT(RARRAY_AREF(a, 1));
 	    df = NUM2INT(RARRAY_AREF(a, 2));
 	    sf = RARRAY_AREF(a, 3);
 	    of = NUM2INT(RARRAY_AREF(a, 4));
 	    sg = NUM2DBL(RARRAY_AREF(a, 5));
-	    if (!df && f_zero_p(sf) && !of) {
-		set_to_simple(self, &dat->s, nth, jd, sg, 0, 0, 0, HAVE_JD);
-	    } else {
-		if (!complex_dat_p(dat))
-		    rb_raise(rb_eArgError,
-			     "cannot load complex into simple");
-
-		set_to_complex(self, &dat->c, nth, jd, df, sf, of, sg,
-			       0, 0, 0, 0, 0, 0,
-			       HAVE_JD | HAVE_DF);
-	    }
 	}
 	break;
       default:
@@ -7197,6 +7171,18 @@ d_lite_marshal_load(VALUE self, VALUE a) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L7171
 	break;
     }
 
+    if (simple_dat_p(dat)) {
+	if (df || !f_zero_p(sf) || of) {
+	    rb_raise(rb_eArgError,
+		     "cannot load complex into simple");
+	}
+	set_to_simple(self, &dat->s, nth, jd, sg, 0, 0, 0, HAVE_JD);
+    } else {
+	set_to_complex(self, &dat->c, nth, jd, df, sf, of, sg,
+		       0, 0, 0, 0, 0, 0,
+		       HAVE_JD | HAVE_DF);
+    }
+
     if (FL_TEST(a, FL_EXIVAR)) {
 	rb_copy_generic_ivar(self, a);
 	FL_SET(self, FL_EXIVAR);
Index: test/date/test_date_marshal.rb
===================================================================
--- test/date/test_date_marshal.rb	(revision 65697)
+++ test/date/test_date_marshal.rb	(revision 65698)
@@ -41,4 +41,12 @@ class TestDateMarshal < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/date/test_date_marshal.rb#L41
     assert_raise(expected_error){d.marshal_load(a)}
   end
 
+  def test_memsize
+    require 'objspace'
+    t = DateTime.new(2018, 11, 13)
+    size = ObjectSpace.memsize_of(t)
+    t2 = Marshal.load(Marshal.dump(t))
+    assert_equal(t, t2)
+    assert_equal(size, ObjectSpace.memsize_of(t2), "not reallocated but memsize changed")
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]