From 1b39a6e539e617f21ce367ee00899f505ddf6c24 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 12 Jan 2016 15:17:19 +0000 Subject: [PATCH] iseq.c: mark parents of wrapped iseq * 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ iseq.c | 4 ++++ test/ruby/bug-11928.rb | 14 ++++++++++++++ test/ruby/test_exception.rb | 6 ++++++ 4 files changed, 30 insertions(+) create mode 100644 test/ruby/bug-11928.rb diff --git a/ChangeLog b/ChangeLog index 29ede23505..d4cb4f52c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Jan 13 00:16:47 2016 Nobuyoshi Nakada + + * 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 * common.mk: update URL and name for the Ruby spec suite. diff --git a/iseq.c b/iseq.c index f72478adfd..8b75ac6cbd 100644 --- a/iseq.c +++ b/iseq.c @@ -711,7 +711,11 @@ rb_iseq_coverage(const rb_iseq_t *iseq) 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 diff --git a/test/ruby/bug-11928.rb b/test/ruby/bug-11928.rb new file mode 100644 index 0000000000..72b3b0f8ed --- /dev/null +++ b/test/ruby/bug-11928.rb @@ -0,0 +1,14 @@ +class Segfault + at_exit { Segfault.new.segfault } + + define_method 'segfault' do + n = 11928 + v = nil + i = 0 + while i < n + i += 1 + v = (foo rescue $!).local_variables + end + assert_equal(%i[i n v], v.sort) + end +end diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 1148277a1b..91732dd062 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -701,6 +701,12 @@ end.join assert_equal(%i[a b c d e f g], e.local_variables.sort) end + def test_name_error_info_parent_iseq_mark + assert_separately(['-', File.join(__dir__, 'bug-11928.rb')], <<-'end;') + -> {require ARGV[0]}.call + end; + end + def test_output_string_encoding # "\x82\xa0" in cp932 is "\u3042" (Japanese hiragana 'a') # change $stderr to force calling rb_io_write() instead of fwrite()