[前][次][番号順一覧][スレッド一覧]

ruby-changes:41377

From: nobu <ko1@a...>
Date: Thu, 7 Jan 2016 14:49:19 +0900 (JST)
Subject: [ruby-changes:41377] nobu:r53449 (trunk): thread.c: interrupt queue on uninitialized thread

nobu	2016-01-07 14:49:31 +0900 (Thu, 07 Jan 2016)

  New Revision: 53449

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53449

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_thread.rb
    trunk/thread.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53448)
+++ ChangeLog	(revision 53449)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jan  7 14:49:12 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* include/ruby/backward.h (ruby_show_copyright_to_die): for source
Index: thread.c
===================================================================
--- thread.c	(revision 53448)
+++ thread.c	(revision 53449)
@@ -1559,6 +1559,14 @@ rb_threadptr_pending_interrupt_enque(rb_ https://github.com/ruby/ruby/blob/trunk/thread.c#L1559
     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, https://github.com/ruby/ruby/blob/trunk/thread.c#L1874
 
     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, VA https://github.com/ruby/ruby/blob/trunk/thread.c#L2190
     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) https://github.com/ruby/ruby/blob/trunk/thread.c#L2235
 	rb_threadptr_to_kill(th);
     }
     else {
+	threadptr_check_pending_interrupt_queue(th);
 	rb_threadptr_pending_interrupt_enque(th, eKillSignal);
 	rb_threadptr_interrupt(th);
     }
Index: test/ruby/test_thread.rb
===================================================================
--- test/ruby/test_thread.rb	(revision 53448)
+++ test/ruby/test_thread.rb	(revision 53449)
@@ -748,9 +748,24 @@ _eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L748
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]