ruby-changes:49297
From: nagachika <ko1@a...>
Date: Fri, 22 Dec 2017 20:43:06 +0900 (JST)
Subject: [ruby-changes:49297] nagachika:r61414 (ruby_2_4): merge revision(s) 57971: [Backport #13305]
nagachika 2017-12-22 20:43:00 +0900 (Fri, 22 Dec 2017) New Revision: 61414 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61414 Log: merge revision(s) 57971: [Backport #13305] Fix a consistency bug of ISEQ_COVERAGE [Bug #13305] There is an invariant that ISEQ_COVERAGE(iseq) must be Qnil if and only if option->coverage_enabled is false. This invariant was broken by NODE_PRELUDE which updates option->coverage_enabled but not ISEQ_COVERAGE(iseq). Modified directories: branches/ruby_2_4/ Modified files: branches/ruby_2_4/compile.c branches/ruby_2_4/test/coverage/test_coverage.rb branches/ruby_2_4/version.h Index: ruby_2_4/compile.c =================================================================== --- ruby_2_4/compile.c (revision 61413) +++ ruby_2_4/compile.c (revision 61414) @@ -6295,14 +6295,17 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/compile.c#L6295 } case NODE_PRELUDE:{ const rb_compile_option_t *orig_opt = ISEQ_COMPILE_DATA(iseq)->option; + VALUE orig_cov = ISEQ_COVERAGE(iseq); + rb_compile_option_t new_opt = *orig_opt; if (node->nd_orig) { - rb_compile_option_t new_opt = *orig_opt; rb_iseq_make_compile_option(&new_opt, node->nd_orig); ISEQ_COMPILE_DATA(iseq)->option = &new_opt; } + if (!new_opt.coverage_enabled) ISEQ_COVERAGE_SET(iseq, Qfalse); CHECK(COMPILE_POPPED(ret, "prelude", node->nd_head)); CHECK(COMPILE_(ret, "body", node->nd_body, popped)); ISEQ_COMPILE_DATA(iseq)->option = orig_opt; + ISEQ_COVERAGE_SET(iseq, orig_cov); break; } case NODE_LAMBDA:{ Index: ruby_2_4/test/coverage/test_coverage.rb =================================================================== --- ruby_2_4/test/coverage/test_coverage.rb (revision 61413) +++ ruby_2_4/test/coverage/test_coverage.rb (revision 61414) @@ -119,4 +119,34 @@ class TestCoverage < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/coverage/test_coverage.rb#L119 end assert_include Coverage.result, "<compiled>" end + + def test_eval + bug13305 = '[ruby-core:80079] [Bug #13305]' + loaded_features = $".dup + + Dir.mktmpdir {|tmp| + Dir.chdir(tmp) { + File.open("test.rb", "w") do |f| + f.puts 'REPEATS = 400' + f.puts 'def add_method(target)' + f.puts ' REPEATS.times do' + f.puts ' target.class_eval(<<~RUBY, __FILE__, __LINE__ + 1)' + f.puts ' def foo' + f.puts ' #{"\n" * rand(REPEATS)}' + f.puts ' end' + f.puts ' 1' + f.puts ' RUBY' + f.puts ' end' + f.puts 'end' + end + + Coverage.start + require tmp + '/test.rb' + add_method(Class.new) + assert_equal Coverage.result[tmp + "/test.rb"], [1, 1, 1, 400, nil, nil, nil, nil, nil, nil, nil], bug13305 + } + } + ensure + $".replace loaded_features + end end unless ENV['COVERAGE'] Index: ruby_2_4/version.h =================================================================== --- ruby_2_4/version.h (revision 61413) +++ ruby_2_4/version.h (revision 61414) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1 #define RUBY_VERSION "2.4.4" -#define RUBY_RELEASE_DATE "2017-12-21" -#define RUBY_PATCHLEVEL 219 +#define RUBY_RELEASE_DATE "2017-12-22" +#define RUBY_PATCHLEVEL 220 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 12 -#define RUBY_RELEASE_DAY 21 +#define RUBY_RELEASE_DAY 22 #include "ruby/version.h" Index: ruby_2_4 =================================================================== --- ruby_2_4 (revision 61413) +++ ruby_2_4 (revision 61414) Property changes on: ruby_2_4 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r57971 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/