mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
error.c: rb_get_backtrace
* error.c (rb_get_backtrace): move from eval_error.c to call exc_backtrace directly. [ruby-core:78097] [Bug #12925] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
48d5a921ab
commit
d432839cbd
4 changed files with 33 additions and 21 deletions
16
error.c
16
error.c
|
@ -882,6 +882,22 @@ exc_backtrace(VALUE exc)
|
|||
return obj;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_get_backtrace(VALUE exc)
|
||||
{
|
||||
VALUE info, klass = rb_eException;
|
||||
ID mid = id_backtrace;
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
if (NIL_P(exc))
|
||||
return Qnil;
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, exc, mid, mid, klass, Qundef);
|
||||
info = exc_backtrace(exc);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, exc, mid, mid, klass, info);
|
||||
if (NIL_P(info))
|
||||
return Qnil;
|
||||
return rb_check_backtrace(info);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* exception.backtrace_locations -> array
|
||||
|
|
4
eval.c
4
eval.c
|
@ -507,7 +507,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
|
|||
rb_ivar_set(mesg, idBt_locations, at);
|
||||
}
|
||||
}
|
||||
else if (NIL_P(get_backtrace(mesg))) {
|
||||
else if (NIL_P(rb_get_backtrace(mesg))) {
|
||||
at = rb_vm_backtrace_object();
|
||||
if (OBJ_FROZEN(mesg)) {
|
||||
mesg = rb_obj_dup(mesg);
|
||||
|
@ -1616,7 +1616,7 @@ errat_getter(ID id)
|
|||
{
|
||||
VALUE err = get_errinfo();
|
||||
if (!NIL_P(err)) {
|
||||
return get_backtrace(err);
|
||||
return rb_get_backtrace(err);
|
||||
}
|
||||
else {
|
||||
return Qnil;
|
||||
|
|
21
eval_error.c
21
eval_error.c
|
@ -49,23 +49,6 @@ error_pos_str(void)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
get_backtrace(VALUE info)
|
||||
{
|
||||
if (NIL_P(info))
|
||||
return Qnil;
|
||||
info = rb_funcall(info, rb_intern("backtrace"), 0);
|
||||
if (NIL_P(info))
|
||||
return Qnil;
|
||||
return rb_check_backtrace(info);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_get_backtrace(VALUE info)
|
||||
{
|
||||
return get_backtrace(info);
|
||||
}
|
||||
|
||||
static void
|
||||
set_backtrace(VALUE info, VALUE bt)
|
||||
{
|
||||
|
@ -80,7 +63,7 @@ set_backtrace(VALUE info, VALUE bt)
|
|||
bt = rb_backtrace_to_str_ary(bt);
|
||||
}
|
||||
}
|
||||
rb_funcall(info, rb_intern("set_backtrace"), 1, bt);
|
||||
rb_check_funcall(info, set_backtrace, 1, &bt);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -105,7 +88,7 @@ rb_threadptr_error_print(rb_thread_t *th, VALUE errinfo)
|
|||
|
||||
TH_PUSH_TAG(th);
|
||||
if (TH_EXEC_TAG() == 0) {
|
||||
errat = get_backtrace(errinfo);
|
||||
errat = rb_get_backtrace(errinfo);
|
||||
}
|
||||
else if (errat == Qundef) {
|
||||
errat = Qnil;
|
||||
|
|
|
@ -952,4 +952,17 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
|
|||
::Warning.warn "\x00a\x00b\x00c".force_encoding("utf-16be")
|
||||
end
|
||||
end
|
||||
|
||||
def test_undefined_backtrace
|
||||
assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
|
||||
begin;
|
||||
class Exception
|
||||
undef backtrace
|
||||
end
|
||||
|
||||
assert_raise(RuntimeError) {
|
||||
raise RuntimeError, "hello"
|
||||
}
|
||||
end;
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue