ruby-changes:48618
From: ko1 <ko1@a...>
Date: Fri, 10 Nov 2017 14:26:58 +0900 (JST)
Subject: [ruby-changes:48618] ko1:r60733 (trunk): refactoring about source line.
ko1 2017-11-10 14:26:52 +0900 (Fri, 10 Nov 2017) New Revision: 60733 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60733 Log: refactoring about source line. * iseq.c (find_line_no): renamed to rb_iseq_line_no(). * vm_backtrace.c (calc_lineno): add a comment why we need to use "pos-1". Modified files: trunk/iseq.c trunk/vm_backtrace.c Index: iseq.c =================================================================== --- iseq.c (revision 60732) +++ iseq.c (revision 60733) @@ -1252,8 +1252,8 @@ get_insn_info(const rb_iseq_t *iseq, siz https://github.com/ruby/ruby/blob/trunk/iseq.c#L1252 return &insns_info[i-1]; } -static unsigned int -find_line_no(const rb_iseq_t *iseq, size_t pos) +unsigned int +rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos) { const struct iseq_insn_info_entry *entry = get_insn_info(iseq, pos); @@ -1265,17 +1265,6 @@ find_line_no(const rb_iseq_t *iseq, size https://github.com/ruby/ruby/blob/trunk/iseq.c#L1265 } } -unsigned int -rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos) -{ - if (pos == 0) { - return find_line_no(iseq, pos); - } - else { - return find_line_no(iseq, pos - 1); - } -} - static VALUE id_to_name(ID id, VALUE default_value) { @@ -1479,8 +1468,8 @@ rb_iseq_disasm_insn(VALUE ret, const VAL https://github.com/ruby/ruby/blob/trunk/iseq.c#L1468 } { - unsigned int line_no = find_line_no(iseq, pos); - unsigned int prev = pos == 0 ? 0 : find_line_no(iseq, pos - 1); + unsigned int line_no = rb_iseq_line_no(iseq, pos); + unsigned int prev = pos == 0 ? 0 : rb_iseq_line_no(iseq, pos - 1); if (line_no && line_no != prev) { long slen = RSTRING_LEN(str); slen = (slen > 70) ? 0 : (70 - slen); @@ -2295,7 +2284,7 @@ rb_iseqw_line_trace_each(VALUE iseqw, in https://github.com/ruby/ruby/blob/trunk/iseq.c#L2284 trace_num++; if (func) { - int line = find_line_no(iseq, pos); + int line = rb_iseq_line_no(iseq, pos); /* printf("line: %d\n", line); */ cont = (*func)(line, &events, data); if (current_events != events) { Index: vm_backtrace.c =================================================================== --- vm_backtrace.c (revision 60732) +++ vm_backtrace.c (revision 60733) @@ -31,7 +31,9 @@ id2str(ID id) https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L31 inline static int calc_lineno(const rb_iseq_t *iseq, const VALUE *pc) { - return rb_iseq_line_no(iseq, pc - iseq->body->iseq_encoded); + size_t pos = (size_t)(pc - iseq->body->iseq_encoded); + /* use pos-1 because PC points next instruction at the beggining of instruction */ + return rb_iseq_line_no(iseq, pos - 1); } int -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/