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

ruby-changes:36748

From: nobu <ko1@a...>
Date: Sat, 13 Dec 2014 20:42:13 +0900 (JST)
Subject: [ruby-changes:36748] nobu:r48829 (trunk): vm_trace.c: defer interrupts while postponed jobs

nobu	2014-12-13 20:41:57 +0900 (Sat, 13 Dec 2014)

  New Revision: 48829

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

  Log:
    vm_trace.c: defer interrupts while postponed jobs
    
    * vm_trace.c (rb_postponed_job_flush): mask signal trap interrupt
      too to defer handling after finalizers finished.
      [ruby-core:66825] [Bug #10595]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_gc.rb
    trunk/vm_trace.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48828)
+++ ChangeLog	(revision 48829)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Dec 13 20:41:55 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_trace.c (rb_postponed_job_flush): mask signal trap interrupt
+	  too to defer handling after finalizers finished.
+	  [ruby-core:66825] [Bug #10595]
+
 Sat Dec 13 18:33:25 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* test/openssl/test_pkey_ec.rb: ignored tests with old OpenSSL.
Index: vm_trace.c
===================================================================
--- vm_trace.c	(revision 48828)
+++ vm_trace.c	(revision 48829)
@@ -1554,12 +1554,13 @@ void https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L1554
 rb_postponed_job_flush(rb_vm_t *vm)
 {
     rb_thread_t *th = GET_THREAD();
-    unsigned long saved_postponed_job_interrupt_mask = th->interrupt_mask & POSTPONED_JOB_INTERRUPT_MASK;
+    const unsigned long block_mask = POSTPONED_JOB_INTERRUPT_MASK|TRAP_INTERRUPT_MASK;
+    unsigned long saved_mask = th->interrupt_mask & block_mask;
     VALUE saved_errno = th->errinfo;
 
     th->errinfo = Qnil;
     /* mask POSTPONED_JOB dispatch */
-    th->interrupt_mask |= POSTPONED_JOB_INTERRUPT_MASK;
+    th->interrupt_mask |= block_mask;
     {
 	TH_PUSH_TAG(th);
 	EXEC_TAG();
@@ -1575,6 +1576,6 @@ rb_postponed_job_flush(rb_vm_t *vm) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L1576
 	TH_POP_TAG();
     }
     /* restore POSTPONED_JOB mask */
-    th->interrupt_mask &= ~(saved_postponed_job_interrupt_mask ^ POSTPONED_JOB_INTERRUPT_MASK);
+    th->interrupt_mask &= ~(saved_mask ^ block_mask);
     th->errinfo = saved_errno;
 }
Index: test/ruby/test_gc.rb
===================================================================
--- test/ruby/test_gc.rb	(revision 48828)
+++ test/ruby/test_gc.rb	(revision 48829)
@@ -331,6 +331,32 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L331
     end;
   end
 
+  def test_interrupt_in_finalizer
+    bug10595 = '[ruby-core:66825] [Bug #10595]'
+    src = <<-'end;'
+      f = proc {1000.times {}}
+      loop do
+        ObjectSpace.define_finalizer(Object.new, f)
+      end
+    end;
+    error = nil
+    status = nil
+    EnvUtil.invoke_ruby(["-e", src], "", false, true) do |_, _, stderr, pid|
+      sleep 0.1
+      Process.kill("INT", pid)
+      th = Thread.start do
+        sleep 1
+        Process.kill("KILL", pid) rescue nil
+      end
+      error = stderr.read
+      _, status = Process.wait2(pid)
+      th.kill
+    end
+    assert_predicate status, :signaled?
+    assert_equal "INT", Signal.signame(status.termsig), bug10595
+    assert_match /Interrupt/, error, bug10595
+  end
+
   def test_verify_internal_consistency
     assert_nil(GC.verify_internal_consistency)
   end

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

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