ruby-changes:44713
From: usa <ko1@a...>
Date: Tue, 15 Nov 2016 03:37:45 +0900 (JST)
Subject: [ruby-changes:44713] usa:r56786 (ruby_2_2): merge revision(s) 56766, 56767: [Backport #12925]
usa 2016-11-15 03:37:39 +0900 (Tue, 15 Nov 2016) New Revision: 56786 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56786 Log: merge revision(s) 56766,56767: [Backport #12925] 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 directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/error.c branches/ruby_2_2/eval.c branches/ruby_2_2/eval_error.c branches/ruby_2_2/test/ruby/test_exception.rb branches/ruby_2_2/version.h Index: ruby_2_2/eval.c =================================================================== --- ruby_2_2/eval.c (revision 56785) +++ ruby_2_2/eval.c (revision 56786) @@ -519,13 +519,25 @@ setup_exception(rb_thread_t *th, int tag https://github.com/ruby/ruby/blob/trunk/ruby_2_2/eval.c#L519 rb_ivar_set(mesg, idBt_locations, at); } } - else if (NIL_P(get_backtrace(mesg))) { - at = rb_vm_backtrace_object(); - if (OBJ_FROZEN(mesg)) { - mesg = rb_obj_dup(mesg); + else { + int status; + + TH_PUSH_TAG(th); + if ((status = EXEC_TAG()) == 0) { + VALUE bt; + if (rb_threadptr_set_raised(th)) goto fatal; + bt = rb_get_backtrace(mesg); + if (NIL_P(bt)) { + at = rb_vm_backtrace_object(); + if (OBJ_FROZEN(mesg)) { + mesg = rb_obj_dup(mesg); + } + rb_ivar_set(mesg, idBt_locations, at); + set_backtrace(mesg, at); + } + rb_threadptr_reset_raised(th); } - rb_ivar_set(mesg, idBt_locations, at); - set_backtrace(mesg, at); + TH_POP_TAG(); } } @@ -567,6 +579,7 @@ setup_exception(rb_thread_t *th, int tag https://github.com/ruby/ruby/blob/trunk/ruby_2_2/eval.c#L579 } if (rb_threadptr_set_raised(th)) { + fatal: th->errinfo = exception_error; rb_threadptr_reset_raised(th); JUMP_TAG(TAG_FATAL); @@ -1587,7 +1600,7 @@ errat_getter(ID id) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/eval.c#L1600 { VALUE err = get_errinfo(); if (!NIL_P(err)) { - return get_backtrace(err); + return rb_get_backtrace(err); } else { return Qnil; Index: ruby_2_2/eval_error.c =================================================================== --- ruby_2_2/eval_error.c (revision 56785) +++ ruby_2_2/eval_error.c (revision 56786) @@ -40,23 +40,6 @@ error_pos(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/eval_error.c#L40 } } -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); -} - VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt); static void @@ -73,7 +56,7 @@ set_backtrace(VALUE info, VALUE bt) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/eval_error.c#L56 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 @@ -93,7 +76,7 @@ error_print(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/eval_error.c#L76 TH_PUSH_TAG(th); if (TH_EXEC_TAG() == 0) { - errat = get_backtrace(errinfo); + errat = rb_get_backtrace(errinfo); } else if (errat == Qundef) { errat = Qnil; Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 56785) +++ ruby_2_2/version.h (revision 56786) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.6" -#define RUBY_RELEASE_DATE "2016-11-12" -#define RUBY_PATCHLEVEL 391 +#define RUBY_RELEASE_DATE "2016-11-15" +#define RUBY_PATCHLEVEL 392 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 11 -#define RUBY_RELEASE_DAY 12 +#define RUBY_RELEASE_DAY 15 #include "ruby/version.h" Index: ruby_2_2/error.c =================================================================== --- ruby_2_2/error.c (revision 56785) +++ ruby_2_2/error.c (revision 56786) @@ -819,6 +819,26 @@ exc_backtrace(VALUE exc) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/error.c#L819 return obj; } +VALUE +rb_get_backtrace(VALUE exc) +{ + ID mid; + CONST_ID(mid, "backtrace"); + if (rb_method_basic_definition_p(CLASS_OF(exc), mid)) { + VALUE info, klass = rb_eException; + rb_thread_t *th = GET_THREAD(); + if (NIL_P(exc)) + return Qnil; + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, exc, mid, klass, Qundef); + info = exc_backtrace(exc); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, exc, mid, klass, info); + if (NIL_P(info)) + return Qnil; + return rb_check_backtrace(info); + } + return rb_funcall(exc, mid, 0, 0); +} + /* * call-seq: * exception.backtrace_locations -> array Index: ruby_2_2/test/ruby/test_exception.rb =================================================================== --- ruby_2_2/test/ruby/test_exception.rb (revision 56785) +++ ruby_2_2/test/ruby/test_exception.rb (revision 56786) @@ -769,4 +769,51 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_exception.rb#L769 assert_raise(NameError) {a.instance_eval("foo")} assert_raise(NoMethodError, bug10969) {a.public_send("bar", true)} end + + def test_undefined_backtrace + assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}") + begin; + class Exception + undef backtrace + end + + assert_raise(RuntimeError) { + raise RuntimeError, "hello" + } + end; + end + + def test_redefined_backtrace + assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}") + begin; + $exc = nil + + class Exception + undef backtrace + def backtrace + $exc = self + end + end + + e = assert_raise(RuntimeError) { + raise RuntimeError, "hello" + } + assert_same(e, $exc) + end; + end + + def test_wrong_backtrace + assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}") + begin; + class Exception + undef backtrace + def backtrace(a) + end + end + + assert_raise(RuntimeError) { + raise RuntimeError, "hello" + } + end; + end end Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r56766-56767 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/