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

ruby-changes:31851

From: nobu <ko1@a...>
Date: Sat, 30 Nov 2013 17:46:49 +0900 (JST)
Subject: [ruby-changes:31851] nobu:r43930 (trunk): eval.c: determine exit status and signal before finalization

nobu	2013-11-30 17:46:41 +0900 (Sat, 30 Nov 2013)

  New Revision: 43930

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

  Log:
    eval.c: determine exit status and signal before finalization
    
    * eval.c (ruby_cleanup): determine exit status and signal to terminate
      before finalization, to get rid of access destroyed T_DATA execption
      object.  [ruby-core:58643] [Bug #9167]

  Added files:
    trunk/ext/-test-/exception/dataerror.c
    trunk/test/-ext-/exception/test_data_error.rb
  Modified files:
    trunk/ChangeLog
    trunk/eval.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43929)
+++ ChangeLog	(revision 43930)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Nov 30 17:46:35 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* eval.c (ruby_cleanup): determine exit status and signal to terminate
+	  before finalization, to get rid of access destroyed T_DATA execption
+	  object.  [ruby-core:58643] [Bug #9167]
+
 Sat Nov 30 16:25:14 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* enumerator.c (enumerator_with_index): should not store local variable
Index: eval.c
===================================================================
--- eval.c	(revision 43929)
+++ eval.c	(revision 43930)
@@ -192,12 +192,6 @@ ruby_cleanup(volatile int ex) https://github.com/ruby/ruby/blob/trunk/eval.c#L192
     }
     th->errinfo = errs[1];
     ex = error_handle(ex);
-    ruby_finalize_1();
-
-    /* unlock again if finalizer took mutexes. */
-    rb_threadptr_unlock_all_locking_mutexes(GET_THREAD());
-    POP_TAG();
-    rb_thread_stop_timer_thread(1);
 
 #if EXIT_SUCCESS != 0 || EXIT_FAILURE != 1
     switch (ex) {
@@ -232,6 +226,13 @@ ruby_cleanup(volatile int ex) https://github.com/ruby/ruby/blob/trunk/eval.c#L226
 	    ex = EXIT_FAILURE;
 	}
     }
+
+    ruby_finalize_1();
+
+    /* unlock again if finalizer took mutexes. */
+    rb_threadptr_unlock_all_locking_mutexes(GET_THREAD());
+    POP_TAG();
+    rb_thread_stop_timer_thread(1);
     ruby_vm_destruct(GET_VM());
     if (state) ruby_default_signal(state);
 
Index: ext/-test-/exception/dataerror.c
===================================================================
--- ext/-test-/exception/dataerror.c	(revision 0)
+++ ext/-test-/exception/dataerror.c	(revision 43930)
@@ -0,0 +1,31 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/exception/dataerror.c#L1
+#include <ruby/ruby.h>
+
+static void
+dataerror_mark(void *ptr)
+{
+    rb_gc_mark((VALUE)ptr);
+}
+
+static void
+dataerror_free(void *ptr)
+{
+}
+
+static const rb_data_type_t dataerror_type = {
+    "Bug #9167",
+    {dataerror_mark, dataerror_free},
+};
+
+static VALUE
+dataerror_alloc(VALUE klass)
+{
+    VALUE n = rb_str_new_cstr("[Bug #9167] error");
+    return TypedData_Wrap_Struct(klass, &dataerror_type, (void *)n);
+}
+
+void
+Init_dataerror(VALUE klass)
+{
+    VALUE rb_eDataErr = rb_define_class_under(klass, "DataError", rb_eStandardError);
+    rb_define_alloc_func(rb_eDataErr, dataerror_alloc);
+}

Property changes on: ext/-test-/exception/dataerror.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: test/-ext-/exception/test_data_error.rb
===================================================================
--- test/-ext-/exception/test_data_error.rb	(revision 0)
+++ test/-ext-/exception/test_data_error.rb	(revision 43930)
@@ -0,0 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/exception/test_data_error.rb#L1
+require 'test/unit'
+require_relative '../../ruby/envutil'
+
+module Bug
+  class TestException < Test::Unit::TestCase
+    def test_cleanup_data_error
+      bug9167 = '[ruby-core:58643] [Bug #9167]'
+      assert_normal_exit(<<-'end;', bug9167) # do
+        require '-test-/exception'
+        raise Bug::Exception::DataError, "Error"
+      end;
+    end
+  end
+end

Property changes on: test/-ext-/exception/test_data_error.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


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

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