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

ruby-changes:28340

From: nobu <ko1@a...>
Date: Sat, 20 Apr 2013 14:22:35 +0900 (JST)
Subject: [ruby-changes:28340] nobu:r40392 (trunk): marshal.c: use ivars of marshal_dump data

nobu	2013-04-20 14:22:25 +0900 (Sat, 20 Apr 2013)

  New Revision: 40392

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40392

  Log:
    marshal.c: use ivars of marshal_dump data
    
    * marshal.c (w_object): dump no ivars to the original by marshal_dump.
      [ruby-core:54334] [Bug #8276]
    * marshal.c (r_object0): copy all ivars of marshal_dump data to the
      result object instead.  [ruby-core:51163] [Bug #7627]

  Modified files:
    trunk/ChangeLog
    trunk/marshal.c
    trunk/test/ruby/test_marshal.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40391)
+++ ChangeLog	(revision 40392)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 20 14:22:10 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* marshal.c (w_object): dump no ivars to the original by marshal_dump.
+	  [ruby-core:54334] [Bug #8276]
+
+	* marshal.c (r_object0): copy all ivars of marshal_dump data to the
+	  result object instead.  [ruby-core:51163] [Bug #7627]
+
 Sat Apr 20 02:33:27 2013  NARUSE, Yui  <naruse@r...>
 
 	* string.c (str_scrub): add ruby method String#scrub which verify and
Index: marshal.c
===================================================================
--- marshal.c	(revision 40391)
+++ marshal.c	(revision 40392)
@@ -598,8 +598,7 @@ w_object(VALUE obj, struct dump_arg *arg https://github.com/ruby/ruby/blob/trunk/marshal.c#L598
     st_table *ivtbl = 0;
     st_data_t num;
     int hasiv = 0;
-#define has_ivars_noenc(obj, ivtbl) (((ivtbl) = rb_generic_ivar_table(obj)) != 0)
-#define has_ivars(obj, ivtbl) (has_ivars_noenc(obj, ivtbl) || \
+#define has_ivars(obj, ivtbl) ((((ivtbl) = rb_generic_ivar_table(obj)) != 0) || \
 			       (!SPECIAL_CONST_P(obj) && !ENCODING_IS_ASCII8BIT(obj)))
 
     if (limit == 0) {
@@ -657,11 +656,8 @@ w_object(VALUE obj, struct dump_arg *arg https://github.com/ruby/ruby/blob/trunk/marshal.c#L656
 
 	    v = rb_funcall2(obj, s_mdump, 0, 0);
 	    check_dump_arg(arg, s_mdump);
-	    hasiv = has_ivars_noenc(v, ivtbl);
-	    if (hasiv) w_byte(TYPE_IVAR, arg);
 	    w_class(TYPE_USRMARSHAL, obj, arg, FALSE);
 	    w_object(v, arg, limit);
-	    if (hasiv) w_ivar(v, ivtbl, &c_arg);
 	    return;
 	}
 	if (rb_obj_respond_to(obj, s_dump, TRUE)) {
@@ -1772,6 +1768,7 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/marshal.c#L1768
 	    VALUE klass = path2class(r_unique(arg));
 	    VALUE oldclass = 0;
 	    VALUE data;
+	    st_table *ivtbl;
 
 	    v = obj_alloc_by_klass(klass, arg, &oldclass);
             if (!NIL_P(extmod)) {
@@ -1787,6 +1784,11 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/marshal.c#L1784
 	    rb_funcall2(v, s_mload, 1, &data);
 	    check_load_arg(arg, s_mload);
             v = r_leave(v, arg);
+	    ivtbl = rb_generic_ivar_table(data);
+	    if (ivtbl && ivtbl->num_entries) {
+		rb_check_frozen(v);
+		rb_copy_generic_ivar(v, data);
+	    }
 	    if (!NIL_P(extmod)) {
 		if (oldclass) append_extmod(v, extmod);
 		rb_ary_clear(extmod);
Index: test/ruby/test_marshal.rb
===================================================================
--- test/ruby/test_marshal.rb	(revision 40391)
+++ test/ruby/test_marshal.rb	(revision 40392)
@@ -553,10 +553,18 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L553
     bug8276 = '[ruby-core:54334] [Bug #8276]'
     t = Bug8276.new(bug8276)
     s = Marshal.dump(t)
-    assert_nothing_raised(RuntimeError) {s = Marshal.load(s)}
+    assert_nothing_raised(RuntimeError, bug8276) {s = Marshal.load(s)}
     assert_equal(t.data, s.data, bug8276)
   end
 
+  def test_marshal_dump_ivar
+    s = "data with ivar"
+    s.instance_variable_set(:@t, 42)
+    t = Bug8276.new(s)
+    s = Marshal.dump(t)
+    assert_raise(RuntimeError) {Marshal.load(s)}
+  end
+
   def test_class_ivar
     assert_raise(TypeError) {Marshal.load("\x04\x08Ic\x1bTestMarshal::TestClass\x06:\x0e@ivar_bug\"\x08bug")}
     assert_raise(TypeError) {Marshal.load("\x04\x08IM\x1bTestMarshal::TestClass\x06:\x0e@ivar_bug\"\x08bug")}

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

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