aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-19 02:42:08 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-19 02:42:08 +0000
commitab81cc4d809437fa1aa71b39bff2587abd8b03df (patch)
tree1ecf71d844bc1cc86d29263977ee0684ea32d23c
parentd61b1e9eaa4d68631d65f484c7dadf5eb80f115c (diff)
downloadruby-ab81cc4d809437fa1aa71b39bff2587abd8b03df.tar.gz
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/ruby/test_thread.rb16
-rw-r--r--thread.c25
2 files changed, 28 insertions, 13 deletions
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index 02f83d05ca..12acedf939 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -366,7 +366,8 @@ class TestThread < Test::Unit::TestCase
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
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
diff --git a/thread.c b/thread.c
index 1fd698c286..4b863eb3e6 100644
--- a/thread.c
+++ b/thread.c
@@ -637,19 +637,20 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s
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;
}