ruby-changes:41450
From: nobu <ko1@a...>
Date: Wed, 13 Jan 2016 16:56:25 +0900 (JST)
Subject: [ruby-changes:41450] nobu:r53524 (trunk): iseq.c: mark parent iseq
nobu 2016-01-13 16:56:51 +0900 (Wed, 13 Jan 2016) New Revision: 53524 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53524 Log: iseq.c: mark parent iseq * iseq.c (rb_iseq_mark): mark parent iseq to prevent dynamically generated iseq by eval from GC. [ruby-core:72620] [Bug #11928] Modified files: trunk/ChangeLog trunk/iseq.c trunk/test/ruby/test_iseq.rb Index: test/ruby/test_iseq.rb =================================================================== --- test/ruby/test_iseq.rb (revision 53523) +++ test/ruby/test_iseq.rb (revision 53524) @@ -185,4 +185,31 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L185 labels = body.select {|op, arg| op == :branchnil}.map {|op, arg| arg} assert_equal(1, labels.uniq.size) end + + def test_parent_iseq_mark + assert_separately([], <<-'end;') + ->{ + ->{ + ->{ + eval <<-EOS + class Segfault + define_method :segfault do + x = nil + GC.disable + 1000.times do |n| + n.times do + x = (foo rescue $!).local_variables + end + GC.start + end + x + end + end + EOS + }.call + }.call + }.call + at_exit { assert_equal([:n, :x], Segfault.new.segfault.sort) } + end; + end end Index: iseq.c =================================================================== --- iseq.c (revision 53523) +++ iseq.c (revision 53524) @@ -113,6 +113,7 @@ rb_iseq_mark(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L113 rb_gc_mark(body->location.base_label); rb_gc_mark(body->location.path); RUBY_MARK_UNLESS_NULL(body->location.absolute_path); + RUBY_MARK_UNLESS_NULL((VALUE)body->parent_iseq); } if (FL_TEST(iseq, ISEQ_NOT_LOADED_YET)) { @@ -711,11 +712,7 @@ rb_iseq_coverage(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L712 static void iseqw_mark(void *ptr) { - const rb_iseq_t *iseq = ptr; rb_gc_mark((VALUE)ptr); - while ((iseq = iseq->body->parent_iseq) != NULL) { - rb_gc_mark((VALUE)iseq); - } } static size_t Index: ChangeLog =================================================================== --- ChangeLog (revision 53523) +++ ChangeLog (revision 53524) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jan 13 16:56:19 2016 Nobuyoshi Nakada <nobu@r...> + + * iseq.c (rb_iseq_mark): mark parent iseq to prevent dynamically + generated iseq by eval from GC. [ruby-core:72620] [Bug #11928] + Wed Jan 13 03:42:58 2016 Eric Wong <e@8...> * class.c (Init_class_hierarchy): resolve name for rb_cObject ASAP @@ -9,12 +14,6 @@ Wed Jan 13 00:37:12 2016 Satoshi Ohmori https://github.com/ruby/ruby/blob/trunk/ChangeLog#L14 * man/ruby.1: fix double word typo. [Fix GH-1194] -Wed Jan 13 00:16:47 2016 Nobuyoshi Nakada <nobu@r...> - - * iseq.c (iseqw_mark): as wrapped iseq is isolated from the call - stack, it needs to take care of its parent and ancestors, so - that they do not become orphans. [ruby-core:72620] [Bug #11928] - Tue Jan 12 21:01:09 2016 Benoit Daloze <eregontp@g...> * common.mk: update URL and name for the Ruby spec suite. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/