summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-26 13:39:15 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-26 13:39:15 (GMT)
commit3d0786a3a80932e99a63497597770fbb94401653 (patch)
treeb1e38be2f0a4004a41c37c912da41a4b61ad718d
parent68d131d6a50898dc605a739caa76b494b65c6393 (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--complex.c1
-rw-r--r--marshal.c4
-rw-r--r--rational.c1
-rw-r--r--test/ruby/test_marshal.rb19
5 files changed, 32 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index edcfcbe..4954aea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Jan 26 22:39:12 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@segment7.net>
* ext/fcntl/fcntl.c: Document Fcntl constants
diff --git a/complex.c b/complex.c
index 2efe6a4..edbe296 100644
--- a/complex.c
+++ b/complex.c
@@ -1324,6 +1324,7 @@ nucomp_marshal_dump(VALUE self)
get_dat1(self);
a = rb_assoc_new(dat->real, dat->imag);
+ rb_copy_generic_ivar(a, self);
return a;
}
diff --git a/marshal.c b/marshal.c
index 786a28b..ba633fa 100644
--- a/marshal.c
+++ b/marshal.c
@@ -651,11 +651,11 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
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)) {
diff --git a/rational.c b/rational.c
index afa4bd4..626d295 100644
--- a/rational.c
+++ b/rational.c
@@ -1583,6 +1583,7 @@ nurat_marshal_dump(VALUE self)
get_dat1(self);
a = rb_assoc_new(dat->num, dat->den);
+ rb_copy_generic_ivar(a, self);
return a;
}
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb
index bc5ee62..74f950b 100644
--- a/test/ruby/test_marshal.rb
+++ b/test/ruby/test_marshal.rb
@@ -517,4 +517,23 @@ class TestMarshal < Test::Unit::TestCase
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