ruby-changes:33285
From: normal <ko1@a...>
Date: Wed, 19 Mar 2014 17:19:17 +0900 (JST)
Subject: [ruby-changes:33285] normal:r45364 (trunk): time.c: freeze and preserve marshal-loaded time zone
normal 2014-03-19 17:19:13 +0900 (Wed, 19 Mar 2014) New Revision: 45364 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45364 Log: time.c: freeze and preserve marshal-loaded time zone We need to prevent vtm.zone from pointing to a GC-ed string buffer. The rb_copy_generic_ivar call misses it because get_attr deleted it. Thanks to nobu for the rb_str_new_frozen suggestion. * time.c (time_mload): freeze and preserve marshal-loaded time zone * test/ruby/test_time.rb: add test for GC on loaded object [Bug #9652] Modified files: trunk/ChangeLog trunk/test/ruby/test_time.rb trunk/time.c Index: time.c =================================================================== --- time.c (revision 45363) +++ time.c (revision 45364) @@ -4827,7 +4827,9 @@ end_submicro: ; https://github.com/ruby/ruby/blob/trunk/time.c#L4827 time_fixoff(time); } if (!NIL_P(zone)) { + zone = rb_str_new_frozen(zone); tobj->vtm.zone = RSTRING_PTR(zone); + rb_ivar_set(time, id_zone, zone); } return time; Index: ChangeLog =================================================================== --- ChangeLog (revision 45363) +++ ChangeLog (revision 45364) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Mar 19 17:13:06 2014 Eric Wong <e@8...> + + * time.c (time_mload): freeze and preserve marshal-loaded time zone + * test/ruby/test_time.rb: add test for GC on loaded object + [Bug #9652] + Tue Mar 18 23:20:12 2014 Shota Fukumori <her@s...> * vm_eval.c (eval_string_with_cref): Unify to use NIL_P. Index: test/ruby/test_time.rb =================================================================== --- test/ruby/test_time.rb (revision 45363) +++ test/ruby/test_time.rb (revision 45364) @@ -310,6 +310,21 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time.rb#L310 end end + def test_marshal_zone_gc + assert_separately(%w(--disable-gems), <<-'end;') + ENV["TZ"] = "Japan" + s = Marshal.dump(Time.now) + t = Marshal.load(s) + n = 0 + done = 1000000 + while t.zone.dup == "JST" && n < done + n += 1 + end + assert_equal n, done, "Bug #9652" + assert_equal "JST", t.zone, "Bug #9652" + end; + end + def test_marshal_to_s t1 = Time.new(2011,11,8, 0,42,25, 9*3600) t2 = Time.at(Marshal.load(Marshal.dump(t1))) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/