mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
marshal.c: no overwriting ivars
* marshal.c (copy_ivar_i): get rid of overwriting already copied instance variales. c.f. [Bug #8276] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b996367eb5
commit
5e79c1a543
3 changed files with 29 additions and 8 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Thu May 2 17:32:45 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* marshal.c (copy_ivar_i): get rid of overwriting already copied
|
||||||
|
instance variales. c.f. [Bug #8276]
|
||||||
|
|
||||||
Thu May 2 16:55:43 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu May 2 16:55:43 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* thread.c (id_locals): use cached ID.
|
* thread.c (id_locals): use cached ID.
|
||||||
|
|
|
@ -1373,7 +1373,11 @@ r_leave(VALUE v, struct load_arg *arg)
|
||||||
static int
|
static int
|
||||||
copy_ivar_i(st_data_t key, st_data_t val, st_data_t arg)
|
copy_ivar_i(st_data_t key, st_data_t val, st_data_t arg)
|
||||||
{
|
{
|
||||||
rb_ivar_set((VALUE)arg, (ID)key, (VALUE)val);
|
VALUE obj = (VALUE)arg, value = (VALUE)val;
|
||||||
|
ID vid = (ID)key;
|
||||||
|
|
||||||
|
if (!rb_ivar_defined(obj, vid))
|
||||||
|
rb_ivar_set(obj, vid, value);
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -555,6 +555,16 @@ class TestMarshal < Test::Unit::TestCase
|
||||||
alias marshal_load initialize
|
alias marshal_load initialize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class FrozenData < LoadData
|
||||||
|
def marshal_load(data)
|
||||||
|
super
|
||||||
|
data.instance_variables.each do |iv|
|
||||||
|
instance_variable_set(iv, data.instance_variable_get(iv))
|
||||||
|
end
|
||||||
|
freeze
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_marshal_dump_excess_encoding
|
def test_marshal_dump_excess_encoding
|
||||||
bug8276 = '[ruby-core:54334] [Bug #8276]'
|
bug8276 = '[ruby-core:54334] [Bug #8276]'
|
||||||
t = Bug8276.new(bug8276)
|
t = Bug8276.new(bug8276)
|
||||||
|
@ -574,18 +584,20 @@ class TestMarshal < Test::Unit::TestCase
|
||||||
def test_marshal_load_ivar
|
def test_marshal_load_ivar
|
||||||
s = "data with ivar"
|
s = "data with ivar"
|
||||||
s.instance_variable_set(:@t, 42)
|
s.instance_variable_set(:@t, 42)
|
||||||
t = LoadData.new(s)
|
|
||||||
s = Marshal.dump(t)
|
|
||||||
hook = ->(v) {
|
hook = ->(v) {
|
||||||
if LoadData === v
|
if LoadData === v
|
||||||
assert_send([v, :instance_variable_defined?, :@t])
|
assert_send([v, :instance_variable_defined?, :@t], v.class.name)
|
||||||
assert_equal(42, v.instance_variable_get(:@t))
|
assert_equal(42, v.instance_variable_get(:@t), v.class.name)
|
||||||
end
|
end
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
v = Marshal.load(s, hook)
|
[LoadData, FrozenData].each do |klass|
|
||||||
assert_send([v, :instance_variable_defined?, :@t])
|
t = klass.new(s)
|
||||||
assert_equal(42, v.instance_variable_get(:@t))
|
d = Marshal.dump(t)
|
||||||
|
v = assert_nothing_raised(RuntimeError) {break Marshal.load(d, hook)}
|
||||||
|
assert_send([v, :instance_variable_defined?, :@t], klass.name)
|
||||||
|
assert_equal(42, v.instance_variable_get(:@t), klass.name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_ivar
|
def test_class_ivar
|
||||||
|
|
Loading…
Add table
Reference in a new issue