diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-19 21:07:54 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-19 21:07:54 +0000 |
commit | 63818379aa3c88681daf634c5f55b2cffac68283 (patch) | |
tree | e31b97f96fd519225c7cd4355f636cff1ac9979c | |
parent | 250fa1cbf04aeea9769be4060825ffcf21f08f91 (diff) |
merge revision(s) 56125,56150: [Backport #12741]
* thread.c (rb_threadptr_raise): set cause from the called thread,
but not from the thread to be interrupted.
[ruby-core:77222] [Bug #12741]
* test/ruby/test_exception.rb: fix thread issues.
* use Queue instead of a local variable for synchronization.
* join created thread to soleve leaking threads warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@58026 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | eval.c | 11 | ||||
-rw-r--r-- | test/ruby/test_exception.rb | 48 | ||||
-rw-r--r-- | thread.c | 3 | ||||
-rw-r--r-- | version.h | 2 |
5 files changed, 75 insertions, 1 deletions
@@ -1,3 +1,15 @@ +Mon Mar 20 05:47:49 2017 Koichi Sasada <ko1@atdot.net> + + * test/ruby/test_exception.rb: fix thread issues. + * use Queue instead of a local variable for synchronization. + * join created thread to soleve leaking threads warning. + +Mon Mar 20 05:47:49 2017 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] + Wed Feb 8 02:17:02 2017 Nobuyoshi Nakada <nobu@ruby-lang.org> * lib/forwardable.rb (Forwardable._delegator_method): extract @@ -581,6 +581,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 cd8743216e..165f679e76 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -703,6 +703,54 @@ end.join assert_equal('d', e.cause.message, 'cause option should be honored always') 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 + q = Queue.new + y = Thread.start do + q.pop + begin + raise "caller's cause" + rescue + x.raise "stop" + end + end + + begin + raise bug12741 + rescue + e = assert_raise_with_message(RuntimeError, "stop") do + q.push(true) + sleep 1 + end + ensure + y.join + end + assert_equal("caller's cause", e.cause.message) + end + def test_unknown_option bug = '[ruby-core:63203] [Feature #8257] should pass unknown options' @@ -2073,6 +2073,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) { @@ -2088,6 +2090,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; @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.3.3" #define RUBY_RELEASE_DATE "2017-03-20" -#define RUBY_PATCHLEVEL 247 +#define RUBY_PATCHLEVEL 248 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 3 |