diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-09 08:59:48 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-09 08:59:48 +0000 |
commit | 646c53895f80358d153d04f04b726d0d14388cf2 (patch) | |
tree | 2a0259c164d7c8c5707931ab306be7ec0015806d | |
parent | b5f3a113f55a81ce19c36b50d1ef234ac518d510 (diff) |
thread.c: set cause by Thread#raise
* thread.c (rb_threadptr_raise): set cause from the called thread,
but not from the thread to be interrupted.
[ruby-core:77222] [Bug #12741]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | eval.c | 11 | ||||
-rw-r--r-- | test/ruby/test_exception.rb | 46 | ||||
-rw-r--r-- | thread.c | 3 |
4 files changed, 66 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Fri Sep 9 17:59:46 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * thread.c (rb_threadptr_raise): set cause from the called thread, + but not from the thread to be interrupted. + [ruby-core:77222] [Bug #12741] + Fri Sep 9 13:50:05 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> * doc/extension.rdoc, doc/extension.ja.rdoc: fix file name. @@ -567,6 +567,17 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause) } } +void +rb_threadptr_setup_exception(rb_thread_t *th, VALUE mesg, VALUE cause) +{ + if (cause == Qundef) { + cause = get_thread_errinfo(th); + } + if (cause != mesg) { + rb_ivar_set(mesg, id_cause, cause); + } +} + static void rb_longjmp(int tag, volatile VALUE mesg, VALUE cause) { diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 5023262e5d..03c0c819f5 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -698,6 +698,52 @@ end.join assert_nil(e.cause.cause) end + def test_cause_thread_no_cause + bug12741 = '[ruby-core:77222] [Bug #12741]' + + x = Thread.current + a = false + y = Thread.start do + Thread.pass until a + x.raise "stop" + end + + begin + raise bug12741 + rescue + e = assert_raise_with_message(RuntimeError, "stop") do + a = true + sleep 1 + end + end + assert_nil(e.cause) + end + + def test_cause_thread_with_cause + bug12741 = '[ruby-core:77222] [Bug #12741]' + + x = Thread.current + a = false + y = Thread.start do + Thread.pass until a + begin + raise "caller's cause" + rescue + x.raise "stop" + end + end + + begin + raise bug12741 + rescue + e = assert_raise_with_message(RuntimeError, "stop") do + a = true + sleep 1 + end + end + assert_equal("caller's cause", e.cause.message) + end + def test_unknown_option bug = '[ruby-core:63203] [Feature #8257] should pass unknown options' @@ -2084,6 +2084,8 @@ rb_threadptr_ready(rb_thread_t *th) rb_threadptr_interrupt(th); } +void rb_threadptr_setup_exception(rb_thread_t *th, VALUE mesg, VALUE cause); + static VALUE rb_threadptr_raise(rb_thread_t *th, int argc, VALUE *argv) { @@ -2099,6 +2101,7 @@ rb_threadptr_raise(rb_thread_t *th, int argc, VALUE *argv) else { exc = rb_make_exception(argc, argv); } + rb_threadptr_setup_exception(GET_THREAD(), exc, Qundef); rb_threadptr_pending_interrupt_enque(th, exc); rb_threadptr_interrupt(th); return Qnil; |