aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-07 05:49:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-07 05:49:31 +0000
commit6899354d47b1f03f8a76d1c1a88d1afa117d8b55 (patch)
treec2f02b87e8bb9e28a4681a2d8841ae3e96fa88e2
parent442eac3f349396c4c977579b519b420af207a831 (diff)
downloadruby-6899354d47b1f03f8a76d1c1a88d1afa117d8b55.tar.gz
thread.c: interrupt queue on uninitialized thread
* thread.c (rb_thread_pending_interrupt_p): no pending interrupt before initialization. * thread.c (thread_raise_m, rb_thread_kill): uninitialized thread cannot interrupt. [ruby-core:72732] [Bug #11959] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--test/ruby/test_thread.rb19
-rw-r--r--thread.c13
3 files changed, 38 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index bfaf2ac69d..4c832bc9fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Jan 7 14:49:12 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * thread.c (rb_thread_pending_interrupt_p): no pending interrupt
+ before initialization.
+
+ * thread.c (thread_raise_m, rb_thread_kill): uninitialized thread
+ cannot interrupt. [ruby-core:72732] [Bug #11959]
+
Thu Jan 7 11:34:14 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/backward.h (ruby_show_copyright_to_die): for source
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index dc929ce4fd..f8036795dc 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -748,9 +748,24 @@ _eom
end
def test_uninitialized
- c = Class.new(Thread)
- c.class_eval { def initialize; end }
+ c = Class.new(Thread) {def initialize; end}
assert_raise(ThreadError) { c.new.start }
+
+ bug11959 = '[ruby-core:72732] [Bug #11959]'
+
+ c = Class.new(Thread) {def initialize; exit; end}
+ assert_raise(ThreadError, bug11959) { c.new }
+
+ c = Class.new(Thread) {def initialize; raise; end}
+ assert_raise(ThreadError, bug11959) { c.new }
+
+ c = Class.new(Thread) {
+ def initialize
+ pending = pending_interrupt?
+ super {pending}
+ end
+ }
+ assert_equal(false, c.new.value, bug11959)
end
def test_backtrace
diff --git a/thread.c b/thread.c
index c9b13bd0c8..bc43572a34 100644
--- a/thread.c
+++ b/thread.c
@@ -1559,6 +1559,14 @@ rb_threadptr_pending_interrupt_enque(rb_thread_t *th, VALUE v)
th->pending_interrupt_queue_checked = 0;
}
+static void
+threadptr_check_pending_interrupt_queue(rb_thread_t *th)
+{
+ if (!th->pending_interrupt_queue) {
+ rb_raise(rb_eThreadError, "uninitialized thread");
+ }
+}
+
enum handle_interrupt_timing {
INTERRUPT_NONE,
INTERRUPT_IMMEDIATE,
@@ -1866,6 +1874,9 @@ rb_thread_pending_interrupt_p(int argc, VALUE *argv, VALUE target_thread)
GetThreadPtr(target_thread, target_th);
+ if (!target_th->pending_interrupt_queue) {
+ return Qfalse;
+ }
if (rb_threadptr_pending_interrupt_empty_p(target_th)) {
return Qfalse;
}
@@ -2179,6 +2190,7 @@ thread_raise_m(int argc, VALUE *argv, VALUE self)
rb_thread_t *target_th;
rb_thread_t *th = GET_THREAD();
GetThreadPtr(self, target_th);
+ threadptr_check_pending_interrupt_queue(target_th);
rb_threadptr_raise(target_th, argc, argv);
/* To perform Thread.current.raise as Kernel.raise */
@@ -2223,6 +2235,7 @@ rb_thread_kill(VALUE thread)
rb_threadptr_to_kill(th);
}
else {
+ threadptr_check_pending_interrupt_queue(th);
rb_threadptr_pending_interrupt_enque(th, eKillSignal);
rb_threadptr_interrupt(th);
}