diff options
-rw-r--r-- | compile.c | 1 | ||||
-rw-r--r-- | iseq.c | 8 | ||||
-rw-r--r-- | node.h | 1 | ||||
-rw-r--r-- | parse.y | 24 | ||||
-rw-r--r-- | test/coverage/test_coverage.rb | 9 | ||||
-rw-r--r-- | vm.c | 1 |
6 files changed, 13 insertions, 31 deletions
@@ -1244,6 +1244,7 @@ new_child_iseq(rb_iseq_t *iseq, const NODE *const node, ast.root = node; ast.compile_option = 0; + ast.line_count = -1; debugs("[new_child_iseq]> ---------------------------------------\n"); ret_iseq = rb_iseq_new_with_opt(&ast, name, @@ -647,6 +647,14 @@ rb_iseq_new(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, rb_iseq_t * rb_iseq_new_top(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent) { + VALUE coverages = rb_get_coverages(); + if (RTEST(coverages)) { + if (ast->line_count >= 0) { + VALUE coverage = rb_default_coverage(ast->line_count); + rb_hash_aset(coverages, path, coverage); + } + } + return rb_iseq_new_with_opt(ast, name, path, realpath, INT2FIX(0), parent, ISEQ_TYPE_TOP, &COMPILE_OPTION_DEFAULT); } @@ -470,6 +470,7 @@ typedef struct node_buffer_struct node_buffer_t; typedef struct rb_ast_body_struct { const NODE *root; VALUE compile_option; + int line_count; } rb_ast_body_t; typedef struct rb_ast_struct { VALUE flags; @@ -266,7 +266,6 @@ struct parser_params { NODE *eval_tree; VALUE error_buffer; VALUE debug_lines; - VALUE coverage; const struct rb_block *base_block; #else /* Ripper only */ @@ -4845,21 +4844,6 @@ debug_lines(VALUE fname) return 0; } -static VALUE -coverage(VALUE fname, int n) -{ - VALUE coverages = rb_get_coverages(); - if (RTEST(coverages) && RBASIC(coverages)->klass == 0) { - VALUE coverage = rb_default_coverage(n); - VALUE lines = RARRAY_AREF(coverage, COVERAGE_INDEX_LINES); - - rb_hash_aset(coverages, fname, coverage); - - return lines == Qnil ? Qfalse : lines; - } - return 0; -} - static int e_option_supplied(struct parser_params *p) { @@ -4885,7 +4869,6 @@ yycompile0(VALUE arg) } if (!e_option_supplied(p)) { - p->coverage = coverage(p->ruby_sourcefile_string, p->ruby_sourceline); cov = Qtrue; } } @@ -4899,7 +4882,6 @@ yycompile0(VALUE arg) n = yyparse(p); RUBY_DTRACE_PARSE_HOOK(END); p->debug_lines = 0; - p->coverage = 0; p->lex.strterm = 0; p->lex.pcur = p->lex.pbeg = p->lex.pend = 0; @@ -4928,6 +4910,7 @@ yycompile0(VALUE arg) p->ast->body.compile_option = opt; } p->ast->body.root = tree; + p->ast->body.line_count = p->line_count; return TRUE; } @@ -4989,10 +4972,8 @@ lex_getline(struct parser_params *p) rb_enc_associate(line, p->enc); rb_ary_push(p->debug_lines, line); } - if (p->coverage) { - rb_ary_push(p->coverage, Qnil); - } #endif + p->line_count++; return line; } @@ -5173,7 +5154,6 @@ nextline(struct parser_params *p) p->heredoc_end = 0; } p->ruby_sourceline++; - p->line_count++; p->lex.pbeg = p->lex.pcur = RSTRING_PTR(v); p->lex.pend = p->lex.pcur + RSTRING_LEN(v); token_flush(p); diff --git a/test/coverage/test_coverage.rb b/test/coverage/test_coverage.rb index 940f5d39be..0b150b8509 100644 --- a/test/coverage/test_coverage.rb +++ b/test/coverage/test_coverage.rb @@ -127,15 +127,6 @@ class TestCoverage < Test::Unit::TestCase } end - def test_nonpositive_linenumber - bug12517 = '[ruby-core:76141] [Bug #12517]' - assert_in_out_err(%w[-W0 -rcoverage], <<-"end;", ['{"<compiled>"=>[nil]}'], [], bug12517) - Coverage.start - RubyVM::InstructionSequence.compile(":ok", nil, "<compiled>", 0) - p Coverage.result - end; - end - def test_eval bug13305 = '[ruby-core:80079] [Bug #13305]' @@ -970,6 +970,7 @@ rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const I rb_node_init(&tmp_node, NODE_SCOPE, (VALUE)dyns, 0, 0); ast.root = &tmp_node; ast.compile_option = 0; + ast.line_count = -1; if (base_iseq) { iseq = rb_iseq_new(&ast, base_iseq->body->location.label, path, realpath, base_iseq, ISEQ_TYPE_EVAL); |