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

ruby-changes:45342

From: nobu <ko1@a...>
Date: Tue, 24 Jan 2017 23:52:13 +0900 (JST)
Subject: [ruby-changes:45342] nobu:r57415 (trunk): eval.c: copy special exception

nobu	2017-01-24 23:52:07 +0900 (Tue, 24 Jan 2017)

  New Revision: 57415

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

  Log:
    eval.c: copy special exception
    
    * eval.c (setup_exception): make unfrozen copy of special
      exception before setting up a cause.

  Modified files:
    trunk/eval.c
    trunk/internal.h
    trunk/test/ruby/test_io.rb
    trunk/vm_insnhelper.c
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 57414)
+++ test/ruby/test_io.rb	(revision 57415)
@@ -3463,5 +3463,25 @@ __END__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L3463
         assert_equal(["foo\n", "bar\n", "baz\n"], IO.readlines(t.path))
       }
     end
+
+    def test_closed_stream_in_rescue
+      100.times do
+        assert_nothing_raised(RuntimeError, /frozen IOError/) do
+          IO.pipe do |r, w|
+            th = Thread.start {r.close}
+            r.gets
+          rescue IOError
+            # swallow pending exceptions
+            begin
+              sleep 0.001
+            rescue IOError
+              retry
+            end
+          ensure
+            th.kill.join
+          end
+        end
+      end
+    end
   end
 end
Index: internal.h
===================================================================
--- internal.h	(revision 57414)
+++ internal.h	(revision 57415)
@@ -1575,7 +1575,7 @@ void rb_vm_pop_cfunc_frame(void); https://github.com/ruby/ruby/blob/trunk/internal.h#L1575
 int rb_vm_add_root_module(ID id, VALUE module);
 void rb_vm_check_redefinition_by_prepend(VALUE klass);
 VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements);
-VALUE ruby_vm_sysstack_error_copy(void);
+VALUE ruby_vm_special_exception_copy(VALUE);
 PUREFUNC(st_table *rb_vm_fstring_table(void));
 
 
Index: eval.c
===================================================================
--- eval.c	(revision 57414)
+++ eval.c	(revision 57415)
@@ -470,6 +470,17 @@ sysstack_error_p(VALUE exc) https://github.com/ruby/ruby/blob/trunk/eval.c#L470
     return exc == sysstack_error || (!SPECIAL_CONST_P(exc) && RBASIC_CLASS(exc) == rb_eSysStackError);
 }
 
+static inline int
+special_exception_p(rb_thread_t *th, VALUE exc)
+{
+    enum ruby_special_exceptions i;
+    const VALUE *exceptions = th->vm->special_exceptions;
+    for (i = 0; i < ruby_special_error_count; ++i) {
+	if (exceptions[i] == exc) return TRUE;
+    }
+    return FALSE;
+}
+
 static void
 setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
 {
@@ -487,6 +498,9 @@ setup_exception(rb_thread_t *th, int tag https://github.com/ruby/ruby/blob/trunk/eval.c#L498
 	mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
 	nocause = 0;
     }
+    else if (special_exception_p(th, mesg)) {
+	mesg = ruby_vm_special_exception_copy(mesg);
+    }
     if (cause != Qundef) {
 	exc_setup_cause(mesg, cause);
     }
@@ -503,9 +517,6 @@ setup_exception(rb_thread_t *th, int tag https://github.com/ruby/ruby/blob/trunk/eval.c#L517
 	if (sysstack_error_p(mesg)) {
 	    if (NIL_P(rb_attr_get(mesg, idBt))) {
 		at = rb_vm_backtrace_object();
-		if (mesg == sysstack_error) {
-		    mesg = ruby_vm_sysstack_error_copy();
-		}
 		rb_ivar_set(mesg, idBt, at);
 		rb_ivar_set(mesg, idBt_locations, at);
 	    }
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 57414)
+++ vm_insnhelper.c	(revision 57415)
@@ -22,17 +22,17 @@ https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L22
 static rb_control_frame_t *vm_get_ruby_level_caller_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp);
 
 VALUE
-ruby_vm_sysstack_error_copy(void)
+ruby_vm_special_exception_copy(VALUE exc)
 {
-    VALUE e = rb_obj_alloc(rb_eSysStackError);
-    rb_obj_copy_ivar(e, sysstack_error);
+    VALUE e = rb_obj_alloc(rb_class_real(RBASIC_CLASS(exc)));
+    rb_obj_copy_ivar(e, exc);
     return e;
 }
 
 static void
 vm_stackoverflow(void)
 {
-    rb_exc_raise(ruby_vm_sysstack_error_copy());
+    rb_exc_raise(ruby_vm_special_exception_copy(sysstack_error));
 }
 
 #if VM_CHECK_MODE > 0

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

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