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

ruby-changes:26900

From: nobu <ko1@a...>
Date: Sat, 26 Jan 2013 22:39:30 +0900 (JST)
Subject: [ruby-changes:26900] nobu:r38952 (trunk): marshal.c: marshal_dump instance varialbes

nobu	2013-01-26 22:39:15 +0900 (Sat, 26 Jan 2013)

  New Revision: 38952

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

  Log:
    marshal.c: marshal_dump instance varialbes
    
    * marshal.c (w_object): dump instance varialbes of the result of
      marshal_dump not the original object.  [ruby-core:51163] [Bug #7627]
    * complex.c (nucomp_marshal_dump): need to copy instance variables.
    * rational.c (nurat_marshal_dump): ditto.

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

Index: complex.c
===================================================================
--- complex.c	(revision 38951)
+++ complex.c	(revision 38952)
@@ -1324,6 +1324,7 @@ nucomp_marshal_dump(VALUE self) https://github.com/ruby/ruby/blob/trunk/complex.c#L1324
     get_dat1(self);
 
     a = rb_assoc_new(dat->real, dat->imag);
+    rb_copy_generic_ivar(a, self);
     return a;
 }
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38951)
+++ ChangeLog	(revision 38952)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jan 26 22:39:12 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* marshal.c (w_object): dump instance varialbes of the result of
+	  marshal_dump not the original object.  [ruby-core:51163] [Bug #7627]
+
+	* complex.c (nucomp_marshal_dump): need to copy instance variables.
+
+	* rational.c (nurat_marshal_dump): ditto.
+
 Sat Jan 26 13:35:56 2013  Eric Hodel  <drbrain@s...>
 
 	* ext/fcntl/fcntl.c:  Document Fcntl constants
Index: marshal.c
===================================================================
--- marshal.c	(revision 38951)
+++ marshal.c	(revision 38952)
@@ -651,11 +651,11 @@ w_object(VALUE obj, struct dump_arg *arg https://github.com/ruby/ruby/blob/trunk/marshal.c#L651
 
 	    v = rb_funcall2(obj, s_mdump, 0, 0);
 	    check_dump_arg(arg, s_mdump);
-	    hasiv = has_ivars(obj, ivtbl);
+	    hasiv = has_ivars(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(obj, ivtbl, &c_arg);
+	    if (hasiv) w_ivar(v, ivtbl, &c_arg);
 	    return;
 	}
 	if (rb_obj_respond_to(obj, s_dump, TRUE)) {
Index: test/ruby/test_marshal.rb
===================================================================
--- test/ruby/test_marshal.rb	(revision 38951)
+++ test/ruby/test_marshal.rb	(revision 38952)
@@ -517,4 +517,23 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L517
       assert(!c.untrusted?, bug7325)
     end
   end
+
+  class Bug7627 < Struct.new(:bar)
+    attr_accessor :foo
+
+    def marshal_dump; 'dump'; end  # fake dump data
+    def marshal_load(*); end       # do nothing
+  end
+
+  def test_marshal_dump_struct_ivar
+    bug7627 = '[ruby-core:51163]'
+    obj = Bug7627.new
+    obj.foo = '[Bug #7627]'
+
+    dump   = Marshal.dump(obj)
+    loaded = Marshal.load(dump)
+
+    assert_equal(obj, loaded, bug7627)
+    assert_nil(loaded.foo, bug7627)
+  end
 end
Index: rational.c
===================================================================
--- rational.c	(revision 38951)
+++ rational.c	(revision 38952)
@@ -1583,6 +1583,7 @@ nurat_marshal_dump(VALUE self) https://github.com/ruby/ruby/blob/trunk/rational.c#L1583
     get_dat1(self);
 
     a = rb_assoc_new(dat->num, dat->den);
+    rb_copy_generic_ivar(a, self);
     return a;
 }
 

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

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