ruby-changes:44693
From: nobu <ko1@a...>
Date: Sun, 13 Nov 2016 14:25:59 +0900 (JST)
Subject: [ruby-changes:44693] nobu:r56766 (trunk): error.c: rb_get_backtrace
nobu 2016-11-13 14:25:53 +0900 (Sun, 13 Nov 2016) New Revision: 56766 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56766 Log: 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] Modified files: trunk/error.c trunk/eval.c trunk/eval_error.c trunk/test/ruby/test_exception.rb Index: error.c =================================================================== --- error.c (revision 56765) +++ error.c (revision 56766) @@ -882,6 +882,22 @@ exc_backtrace(VALUE exc) https://github.com/ruby/ruby/blob/trunk/error.c#L882 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 Index: test/ruby/test_exception.rb =================================================================== --- test/ruby/test_exception.rb (revision 56765) +++ test/ruby/test_exception.rb (revision 56766) @@ -952,4 +952,17 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L952 ::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 Index: eval.c =================================================================== --- eval.c (revision 56765) +++ eval.c (revision 56766) @@ -507,7 +507,7 @@ setup_exception(rb_thread_t *th, int tag https://github.com/ruby/ruby/blob/trunk/eval.c#L507 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) https://github.com/ruby/ruby/blob/trunk/eval.c#L1616 { VALUE err = get_errinfo(); if (!NIL_P(err)) { - return get_backtrace(err); + return rb_get_backtrace(err); } else { return Qnil; Index: eval_error.c =================================================================== --- eval_error.c (revision 56765) +++ eval_error.c (revision 56766) @@ -49,23 +49,6 @@ error_pos_str(void) https://github.com/ruby/ruby/blob/trunk/eval_error.c#L49 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) https://github.com/ruby/ruby/blob/trunk/eval_error.c#L63 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 https://github.com/ruby/ruby/blob/trunk/eval_error.c#L88 TH_PUSH_TAG(th); if (TH_EXEC_TAG() == 0) { - errat = get_backtrace(errinfo); + errat = rb_get_backtrace(errinfo); } else if (errat == Qundef) { errat = Qnil; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/