summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-19 21:07:54 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-19 21:07:54 +0000
commit63818379aa3c88681daf634c5f55b2cffac68283 (patch)
treee31b97f96fd519225c7cd4355f636cff1ac9979c
parent250fa1cbf04aeea9769be4060825ffcf21f08f91 (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--ChangeLog12
-rw-r--r--eval.c11
-rw-r--r--test/ruby/test_exception.rb48
-rw-r--r--thread.c3
-rw-r--r--version.h2
5 files changed, 75 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 1d8773dae2..e0b959d32a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/eval.c b/eval.c
index e3dbb9eb66..3a9e25c8b4 100644
--- a/eval.c
+++ b/eval.c
@@ -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'
diff --git a/thread.c b/thread.c
index e48c05e996..3ec4b900a7 100644
--- a/thread.c
+++ b/thread.c
@@ -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;
diff --git a/version.h b/version.h
index 78c26e60aa..0628afac17 100644
--- a/version.h
+++ b/version.h
@@ -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