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

ruby-changes:27104

From: nobu <ko1@a...>
Date: Fri, 8 Feb 2013 16:12:57 +0900 (JST)
Subject: [ruby-changes:27104] nobu:r39156 (trunk): eval.c: preserve errinfo

nobu	2013-02-08 16:09:48 +0900 (Fri, 08 Feb 2013)

  New Revision: 39156

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

  Log:
    eval.c: preserve errinfo
    
    * eval.c (rb_ensure): preserve errinfo accross ensure proc before
      JUMP_TAG().  [ruby-core:52022] [Bug #7802]

  Added files:
    trunk/ext/-test-/exception/ensured.c
    trunk/test/-ext-/exception/test_ensured.rb
  Modified files:
    trunk/ChangeLog
    trunk/eval.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39155)
+++ ChangeLog	(revision 39156)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Feb  8 16:09:45 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* eval.c (rb_ensure): preserve errinfo accross ensure proc before
+	  JUMP_TAG().  [ruby-core:52022] [Bug #7802]
+
 Fri Feb  8 16:08:28 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* test/ruby/envutil.rb (assert_separately): check also terminating
Index: eval.c
===================================================================
--- eval.c	(revision 39155)
+++ eval.c	(revision 39156)
@@ -805,6 +805,8 @@ rb_ensure(VALUE (*b_proc)(ANYARGS), VALU https://github.com/ruby/ruby/blob/trunk/eval.c#L805
 {
     int state;
     volatile VALUE result = Qnil;
+    volatile VALUE errinfo;
+    rb_thread_t *const th = GET_THREAD();
 
     PUSH_TAG();
     if ((state = EXEC_TAG()) == 0) {
@@ -813,7 +815,9 @@ rb_ensure(VALUE (*b_proc)(ANYARGS), VALU https://github.com/ruby/ruby/blob/trunk/eval.c#L815
     POP_TAG();
     /* TODO: fix me */
     /* retval = prot_tag ? prot_tag->retval : Qnil; */     /* save retval */
+    errinfo = th->errinfo;
     (*e_proc) (data2);
+    th->errinfo = errinfo;
     if (state)
 	JUMP_TAG(state);
     return result;
Index: ext/-test-/exception/ensured.c
===================================================================
--- ext/-test-/exception/ensured.c	(revision 0)
+++ ext/-test-/exception/ensured.c	(revision 39156)
@@ -0,0 +1,25 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/exception/ensured.c#L1
+#include <ruby.h>
+
+static VALUE
+begin(VALUE object)
+{
+    return rb_funcall(object, rb_intern("try_method"), 0);
+}
+
+static VALUE
+ensure(VALUE object)
+{
+    return rb_funcall(object, rb_intern("ensured_method"), 0);
+}
+
+static VALUE
+ensured(VALUE module, VALUE object)
+{
+    return rb_ensure(begin, object, ensure, object);
+}
+
+void
+Init_ensured(VALUE klass)
+{
+    rb_define_module_function(klass, "ensured", ensured, 1);
+}

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

Index: test/-ext-/exception/test_ensured.rb
===================================================================
--- test/-ext-/exception/test_ensured.rb	(revision 0)
+++ test/-ext-/exception/test_ensured.rb	(revision 39156)
@@ -0,0 +1,32 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/exception/test_ensured.rb#L1
+require 'test/unit'
+require_relative '../../ruby/envutil'
+
+module Bug
+  class Bug7802 < RuntimeError
+  end
+
+  class TestException < Test::Unit::TestCase
+    def test_ensured
+      assert_separately([], <<-'end;') # do
+
+        require '-test-/exception'
+
+        module Bug
+          class Bug7802 < RuntimeError
+            def try_method
+              raise self
+            end
+
+            def ensured_method
+              [1].detect {|i| true}
+            end
+          end
+        end
+
+        assert_raise(Bug::Bug7802, '[ruby-core:52022] [Bug #7802]') {
+          Bug::Exception.ensured(Bug::Bug7802.new)
+        }
+      end;
+    end
+  end
+end

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


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

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