ruby-changes:53401
From: nobu <ko1@a...>
Date: Thu, 8 Nov 2018 10:57:07 +0900 (JST)
Subject: [ruby-changes:53401] nobu:r65617 (trunk): compile.c: compile error than rb_bug [ci skip]
nobu 2018-11-08 10:57:03 +0900 (Thu, 08 Nov 2018) New Revision: 65617 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65617 Log: compile.c: compile error than rb_bug [ci skip] * compile.c (get_local_var_idx, get_dyna_var_idx): raise a compile error which is useful than rb_bug, when ID is not found. * compile.c (iseq_set_sequence): ditto when IC index overflow, with dumping generated code. Modified files: trunk/compile.c Index: compile.c =================================================================== --- compile.c (revision 65616) +++ compile.c (revision 65617) @@ -370,7 +370,7 @@ NORETURN(static void append_compile_erro https://github.com/ruby/ruby/blob/trunk/compile.c#L370 #endif static void -append_compile_error(rb_iseq_t *iseq, int line, const char *fmt, ...) +append_compile_error(const rb_iseq_t *iseq, int line, const char *fmt, ...) { VALUE err_info = ISEQ_COMPILE_DATA(iseq)->err_info; VALUE file = rb_iseq_path(iseq); @@ -567,6 +567,8 @@ APPEND_ELEM(ISEQ_ARG_DECLARE LINK_ANCHOR https://github.com/ruby/ruby/blob/trunk/compile.c#L567 #define APPEND_ELEM(anchor, before, elem) APPEND_ELEM(iseq, (anchor), (before), (elem)) #endif +#define ISEQ_LAST_LINE(iseq) (ISEQ_COMPILE_DATA(iseq)->last_line) + static int iseq_add_mark_object_compile_time(const rb_iseq_t *iseq, VALUE v) { @@ -1393,7 +1395,8 @@ get_local_var_idx(const rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L1395 int idx = get_dyna_var_idx_at_raw(iseq->body->local_iseq, id); if (idx < 0) { - rb_bug("get_local_var_idx: %d", idx); + COMPILE_ERROR(iseq, ISEQ_LAST_LINE(iseq), + "get_local_var_idx: %d", idx); } return idx; @@ -1414,7 +1417,8 @@ get_dyna_var_idx(const rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L1417 } if (idx < 0) { - rb_bug("get_dyna_var_idx: -1"); + COMPILE_ERROR(iseq, ISEQ_LAST_LINE(iseq), + "get_dyna_var_idx: -1"); } *level = lv; @@ -2154,7 +2158,10 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L2158 unsigned int ic_index = FIX2UINT(operands[j]); IC ic = (IC)&body->is_entries[ic_index]; if (UNLIKELY(ic_index >= body->is_size)) { - rb_bug("iseq_set_sequence: ic_index overflow: index: %d, size: %d", ic_index, body->is_size); + BADINSN_DUMP(anchor, &iobj->link, 0); + COMPILE_ERROR(iseq, iobj->insn_info.line_no, + "iseq_set_sequence: ic_index overflow: index: %d, size: %d", + ic_index, body->is_size); } generated_iseq[code_index + 1 + j] = (VALUE)ic; break; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/