ruby-changes:47843
From: nobu <ko1@a...>
Date: Tue, 19 Sep 2017 11:42:12 +0900 (JST)
Subject: [ruby-changes:47843] nobu:r59963 (trunk): thread.c: report then abort
nobu 2017-09-19 11:42:08 +0900 (Tue, 19 Sep 2017) New Revision: 59963 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59963 Log: thread.c: report then abort * thread.c (thread_start_func_2): report then abort on exception, if both are set. [ruby-core:79280] [Bug #13163] Modified files: trunk/test/ruby/test_thread.rb trunk/thread.c Index: test/ruby/test_thread.rb =================================================================== --- test/ruby/test_thread.rb (revision 59962) +++ test/ruby/test_thread.rb (revision 59963) @@ -366,7 +366,8 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L366 end def test_report_on_exception - assert_separately([], <<~"end;") #do + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; q1 = Thread::Queue.new q2 = Thread::Queue.new @@ -418,6 +419,19 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L419 assert_equal(true, q1.pop) Thread.pass while th.alive? } + + assert_warn(/report 5/, "should defaults to the global flag at the start") { + th = Thread.start { + Thread.current.report_on_exception = true + Thread.current.abort_on_exception = true + q2.pop + raise "report 5" + } + assert_raise_with_message(RuntimeError, "report 5") { + q2.push(true) + Thread.pass while th.alive? + } + } end; end Index: thread.c =================================================================== --- thread.c (revision 59962) +++ thread.c (revision 59963) @@ -637,19 +637,20 @@ thread_start_func_2(rb_thread_t *th, VAL https://github.com/ruby/ruby/blob/trunk/thread.c#L637 else if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) { /* exit on main_thread. */ } - else if (th->vm->thread_abort_on_exception || - th->abort_on_exception || RTEST(ruby_debug)) { - /* exit on main_thread */ - } - else if (th->report_on_exception) { - VALUE mesg = rb_thread_to_s(th->self); - rb_str_cat_cstr(mesg, " terminated with exception:\n"); - rb_write_error_str(mesg); - rb_threadptr_error_print(th, errinfo); - errinfo = Qnil; - } else { - errinfo = Qnil; + if (th->report_on_exception) { + VALUE mesg = rb_thread_to_s(th->self); + rb_str_cat_cstr(mesg, " terminated with exception:\n"); + rb_write_error_str(mesg); + rb_threadptr_error_print(th, errinfo); + } + if (th->vm->thread_abort_on_exception || + th->abort_on_exception || RTEST(ruby_debug)) { + /* exit on main_thread */ + } + else { + errinfo = Qnil; + } } th->value = Qnil; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/