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

ruby-changes:7861

From: tadf <ko1@a...>
Date: Tue, 16 Sep 2008 19:21:45 +0900 (JST)
Subject: [ruby-changes:7861] Ruby:r19382 (trunk): * complex.c (nucomp_marshal_{dump,load}): preserve instance

tadf	2008-09-16 19:21:23 +0900 (Tue, 16 Sep 2008)

  New Revision: 19382

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

  Log:
    * complex.c (nucomp_marshal_{dump,load}): preserve instance
      variables.
    
    * rational.c (nurat_marshal_{dump,load}): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/complex.c
    trunk/rational.c
    trunk/test/ruby/test_complex.rb
    trunk/test/ruby/test_rational.rb

Index: complex.c
===================================================================
--- complex.c	(revision 19381)
+++ complex.c	(revision 19382)
@@ -937,8 +937,12 @@
 static VALUE
 nucomp_marshal_dump(VALUE self)
 {
+    VALUE a;
     get_dat1(self);
-    return rb_assoc_new(dat->real, dat->image);
+
+    a = rb_assoc_new(dat->real, dat->image);
+    rb_copy_generic_ivar(a, self);
+    return a;
 }
 
 static VALUE
@@ -947,6 +951,7 @@
     get_dat1(self);
     dat->real = RARRAY_PTR(a)[0];
     dat->image = RARRAY_PTR(a)[1];
+    rb_copy_generic_ivar(self, a);
     return self;
 }
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19381)
+++ ChangeLog	(revision 19382)
@@ -1,3 +1,10 @@
+Tue Sep 16 19:18:40 2008  Tadayoshi Funaba  <tadf@d...>
+
+	* complex.c (nucomp_marshal_{dump,load}): preserve instance
+	  variables.
+
+	* rational.c (nurat_marshal_{dump,load}): ditto.
+
 Tue Sep 16 18:28:52 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* io.c (rb_io_gets_m): rdoc updated.  limit counts in bytes.
@@ -251,7 +258,7 @@
 
 Sun Sep 14 10:10:43 2008  Tadayoshi Funaba  <tadf@d...>
 
-	* complex.c (f_{add,mul,sub}): omitted some shortcuts for preserve
+	* complex.c (f_{add,mul,sub}): omitted some shortcuts for preserving
 	  signed zero anyway.
 
 	* complex.c (nucomp_negate): new.
Index: test/ruby/test_complex.rb
===================================================================
--- test/ruby/test_complex.rb	(revision 19381)
+++ test/ruby/test_complex.rb	(revision 19382)
@@ -638,10 +638,12 @@
 
   def test_marshal
     c = Complex(1,2)
+    c.instance_eval{@ivar = 9}
 
     s = Marshal.dump(c)
     c2 = Marshal.load(s)
     assert_equal(c, c2)
+    assert_equal(9, c2.instance_variable_get(:@ivar))
     assert_instance_of(Complex, c2)
 
     if defined?(Rational)
Index: test/ruby/test_rational.rb
===================================================================
--- test/ruby/test_rational.rb	(revision 19381)
+++ test/ruby/test_rational.rb	(revision 19382)
@@ -854,10 +854,12 @@
 
   def test_marshal
     c = Rational(1,2)
+    c.instance_eval{@ivar = 9}
 
     s = Marshal.dump(c)
     c2 = Marshal.load(s)
     assert_equal(c, c2)
+    assert_equal(9, c2.instance_variable_get(:@ivar))
     assert_instance_of(Rational, c2)
 
     assert_raise(ZeroDivisionError){
Index: rational.c
===================================================================
--- rational.c	(revision 19381)
+++ rational.c	(revision 19382)
@@ -1125,8 +1125,12 @@
 static VALUE
 nurat_marshal_dump(VALUE self)
 {
+    VALUE a;
     get_dat1(self);
-    return rb_assoc_new(dat->num, dat->den);
+
+    a = rb_assoc_new(dat->num, dat->den);
+    rb_copy_generic_ivar(a, self);
+    return a;
 }
 
 static VALUE
@@ -1135,6 +1139,7 @@
     get_dat1(self);
     dat->num = RARRAY_PTR(a)[0];
     dat->den = RARRAY_PTR(a)[1];
+    rb_copy_generic_ivar(self, a);
 
     if (f_zero_p(dat->den))
 	rb_raise_zerodiv();

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

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