From dc4fbc46861900429d621ae7b00b76593df88719 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 4 Oct 2009 10:30:56 +0000 Subject: * marshal.c (struct {dump,load}_arg): manage with dfree, instead of using local variable which may be moved by context switch. [ruby-dev:39425] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_marshal.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb index a69770663..676953930 100644 --- a/test/ruby/test_marshal.rb +++ b/test/ruby/test_marshal.rb @@ -212,4 +212,45 @@ class TestMarshal < Test::Unit::TestCase c = [/#{a}/, /#{b}/] assert_equal(c, Marshal.load(Marshal.dump(c))) end + + class DumpTest + def marshal_dump + @@block.call(:marshal_dump) + end + + def dump_each(&block) + @@block = block + Marshal.dump(self) + end + end + + class LoadTest + def marshal_dump + nil + end + def marshal_load(obj) + @@block.call(:marshal_load) + end + def self.load_each(m, &block) + @@block = block + Marshal.load(m) + end + end + + def test_context_switch + o = DumpTest.new + e = o.enum_for(:dump_each) + assert_equal(:marshal_dump, e.next) + GC.start + assert(true, '[ruby-dev:39425]') + assert_raise(StopIteration) {e.next} + + o = LoadTest.new + m = Marshal.dump(o) + e = LoadTest.enum_for(:load_each, m) + assert_equal(:marshal_load, e.next) + GC.start + assert(true, '[ruby-dev:39425]') + assert_raise(StopIteration) {e.next} + end end -- cgit