summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-25 17:13:49 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-25 17:13:49 +0000
commitda0e21528bd64a931e2f956c216455d7180f57d8 (patch)
treee37038c1a7f34da2c30ebbebe3c30c9d09bf960d
parent134c045f1d5eb7273bba721fc1c997050c43e24d (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_2@58107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--eval.c11
-rw-r--r--test/ruby/test_exception.rb46
-rw-r--r--thread.c3
-rw-r--r--version.h2
5 files changed, 73 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index ff0a0f78f5..375befc589 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Sun Mar 26 02:13:04 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.
+
+Sun Mar 26 02:13:04 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]
+
Sat Mar 25 23:35:54 2017 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/forwardable.rb (Forwardable._delegator_method): extract
diff --git a/eval.c b/eval.c
index fbd28565ed..5eba8fdce7 100644
--- a/eval.c
+++ b/eval.c
@@ -595,6 +595,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 3268096463..d0df4a9b74 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -696,6 +696,52 @@ 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
+ 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'
diff --git a/thread.c b/thread.c
index 0fd711aaff..da607b2dbb 100644
--- a/thread.c
+++ b/thread.c
@@ -2046,6 +2046,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)
{
@@ -2061,6 +2063,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;
diff --git a/version.h b/version.h
index 2d26d3d6c6..cbc9b2e9a4 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.2.7"
#define RUBY_RELEASE_DATE "2017-03-26"
-#define RUBY_PATCHLEVEL 439
+#define RUBY_PATCHLEVEL 440
#define RUBY_RELEASE_YEAR 2017
#define RUBY_RELEASE_MONTH 3