vm_eval.c: strange message in eval

* vm_eval.c (eval_string_with_cref): remove unnecessary location
  from exception backtrace in eval.
  [ruby-core:84434] [Bug #14229]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61482 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-12-26 09:05:28 +00:00
Родитель 9e717416b4
Коммит 62a3e7a33b
2 изменённых файлов: 10 добавлений и 40 удалений

Просмотреть файл

@ -1101,6 +1101,11 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
end;
end
def test_backtrace_in_eval
bug = '[ruby-core:84434] [Bug #14229]'
assert_in_out_err(['-e', 'eval("raise")'], "", [], /^\(eval\):1:/, bug)
end
def test_full_message
test_method = "def foo; raise 'testerror'; end"

Просмотреть файл

@ -1242,34 +1242,15 @@ rb_each(VALUE obj)
return rb_call(obj, idEach, 0, 0, CALL_FCALL);
}
static VALUE
adjust_backtrace_in_eval(const rb_execution_context_t *ec, VALUE errinfo)
{
VALUE errat = rb_get_backtrace(errinfo);
VALUE mesg = rb_attr_get(errinfo, id_mesg);
if (RB_TYPE_P(errat, T_ARRAY)) {
VALUE bt2 = rb_ec_backtrace_str_ary(ec, 0, 0);
if (RARRAY_LEN(bt2) > 0) {
if (RB_TYPE_P(mesg, T_STRING) && !RSTRING_LEN(mesg)) {
rb_ivar_set(errinfo, id_mesg, RARRAY_AREF(errat, 0));
}
RARRAY_ASET(errat, 0, RARRAY_AREF(bt2, 0));
}
}
return errinfo;
}
static VALUE
eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_arg,
VALUE filename, int lineno)
{
int state;
VALUE result = Qundef;
rb_execution_context_t *ec = GET_EC();
struct rb_block block;
const struct rb_block *base_block;
volatile VALUE file;
volatile int line;
VALUE file;
int line;
file = filename ? filename : rb_source_location(&lineno);
line = lineno;
@ -1318,7 +1299,7 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_
iseq = rb_iseq_compile_with_option(src, fname, realpath, INT2FIX(line), base_block, Qnil);
if (!iseq) {
rb_exc_raise(adjust_backtrace_in_eval(ec, ec->errinfo));
rb_exc_raise(ec->errinfo);
}
/* TODO: what the code checking? */
@ -1344,24 +1325,8 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_
}
}
if (file != Qundef) {
/* kick */
return vm_exec(ec);
}
EC_PUSH_TAG(ec);
if ((state = EC_EXEC_TAG()) == TAG_NONE) {
result = vm_exec(ec);
}
EC_POP_TAG();
if (state) {
if (state == TAG_RAISE) {
adjust_backtrace_in_eval(ec, ec->errinfo);
}
EC_JUMP_TAG(ec, state);
}
return result;
/* kick */
return vm_exec(ec);
}
static VALUE