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

ruby-changes:45437

From: nobu <ko1@a...>
Date: Fri, 3 Feb 2017 15:23:39 +0900 (JST)
Subject: [ruby-changes:45437] nobu:r57510 (trunk): eval.c: hide internal objects

nobu	2017-02-03 15:23:34 +0900 (Fri, 03 Feb 2017)

  New Revision: 57510

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

  Log:
    eval.c: hide internal objects
    
    * eval.c (rb_ensure): veil internal exception objects not to leak
      in ensure functions.  [ruby-core:79371] [Bug #13176]

  Added files:
    trunk/test/-ext-/exception/test_exception_at_throwing.rb
  Modified files:
    trunk/eval.c
    trunk/ext/-test-/exception/ensured.c
Index: ext/-test-/exception/ensured.c
===================================================================
--- ext/-test-/exception/ensured.c	(revision 57509)
+++ ext/-test-/exception/ensured.c	(revision 57510)
@@ -18,8 +18,22 @@ ensured(VALUE module, VALUE object) https://github.com/ruby/ruby/blob/trunk/ext/-test-/exception/ensured.c#L18
     return rb_ensure(begin, object, ensure, object);
 }
 
+static VALUE
+raise(VALUE exc)
+{
+    rb_exc_raise(exc);
+    return Qnil;
+}
+
+static VALUE
+ensure_raise(VALUE module, VALUE object, VALUE exc)
+{
+    return rb_ensure(rb_yield, object, raise, exc);
+}
+
 void
 Init_ensured(VALUE klass)
 {
     rb_define_module_function(klass, "ensured", ensured, 1);
+    rb_define_module_function(klass, "ensure_raise", ensure_raise, 2);
 }
Index: eval.c
===================================================================
--- eval.c	(revision 57509)
+++ eval.c	(revision 57510)
@@ -924,7 +924,7 @@ rb_ensure(VALUE (*b_proc)(ANYARGS), VALU https://github.com/ruby/ruby/blob/trunk/eval.c#L924
 {
     int state;
     volatile VALUE result = Qnil;
-    volatile VALUE errinfo;
+    VALUE errinfo;
     rb_thread_t *const th = GET_THREAD();
     rb_ensure_list_t ensure_list;
     ensure_list.entry.marker = 0;
@@ -938,6 +938,9 @@ rb_ensure(VALUE (*b_proc)(ANYARGS), VALU https://github.com/ruby/ruby/blob/trunk/eval.c#L938
     }
     TH_POP_TAG();
     errinfo = th->errinfo;
+    if (!NIL_P(errinfo) && !RB_TYPE_P(errinfo, T_OBJECT)) {
+	th->errinfo = Qnil;
+    }
     th->ensure_list=ensure_list.next;
     (*ensure_list.entry.e_proc)(ensure_list.entry.data2);
     th->errinfo = errinfo;
Index: test/-ext-/exception/test_exception_at_throwing.rb
===================================================================
--- test/-ext-/exception/test_exception_at_throwing.rb	(revision 0)
+++ test/-ext-/exception/test_exception_at_throwing.rb	(revision 57510)
@@ -0,0 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/exception/test_exception_at_throwing.rb#L1
+# frozen_string_literal: true
+require 'test/unit'
+
+module Bug
+  class TestException < Test::Unit::TestCase
+    def test_exception_at_throwing
+      assert_separately(%w[-r-test-/exception], "#{<<-"begin;"}\n#{<<-"end;"}")
+      begin;
+        e = RuntimeError.new("[Bug #13176]")
+        assert_raise_with_message(e.class, e.message) do
+          catch do |t|
+            Bug::Exception.ensure_raise(nil, e) {throw t}
+          end
+        end
+      end;
+    end
+  end
+end

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


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

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