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

ruby-changes:42601

From: usa <ko1@a...>
Date: Fri, 22 Apr 2016 13:41:32 +0900 (JST)
Subject: [ruby-changes:42601] usa:r54675 (ruby_2_2): merge revision(s) 53819, 53822: [Backport #12068]

usa	2016-04-22 14:38:08 +0900 (Fri, 22 Apr 2016)

  New Revision: 54675

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

  Log:
    merge revision(s) 53819,53822: [Backport #12068]
    
    * eval.c (setup_exception): set the cause only if it is explicitly
      given or not set yet.  [Bug #12068]

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ChangeLog
    branches/ruby_2_2/eval.c
    branches/ruby_2_2/test/ruby/test_exception.rb
    branches/ruby_2_2/version.h
Index: ruby_2_2/eval.c
===================================================================
--- ruby_2_2/eval.c	(revision 54674)
+++ ruby_2_2/eval.c	(revision 54675)
@@ -24,6 +24,8 @@ NORETURN(void rb_raise_jump(VALUE, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_2/eval.c#L24
 VALUE rb_eLocalJumpError;
 VALUE rb_eSysStackError;
 
+static ID id_cause;
+
 #define exception_error GET_VM()->special_exceptions[ruby_error_reenter]
 
 #include "eval_error.c"
@@ -450,9 +452,6 @@ static VALUE get_thread_errinfo(rb_threa https://github.com/ruby/ruby/blob/trunk/ruby_2_2/eval.c#L452
 static VALUE
 exc_setup_cause(VALUE exc, VALUE cause)
 {
-    ID id_cause;
-    CONST_ID(id_cause, "cause");
-
 #if SUPPORT_JOKE
     if (NIL_P(cause)) {
 	ID id_true_cause;
@@ -496,10 +495,15 @@ setup_exception(rb_thread_t *th, int tag https://github.com/ruby/ruby/blob/trunk/ruby_2_2/eval.c#L495
 	mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
 	nocause = 0;
     }
-    if (cause == Qundef) {
-	cause = nocause ? Qnil : get_thread_errinfo(th);
+    if (cause != Qundef) {
+	exc_setup_cause(mesg, cause);
+    }
+    else if (nocause) {
+	exc_setup_cause(mesg, Qnil);
+    }
+    else if (!rb_ivar_defined(mesg, id_cause)) {
+	exc_setup_cause(mesg, get_thread_errinfo(th));
     }
-    exc_setup_cause(mesg, cause);
 
     file = rb_sourcefile();
     if (file) line = rb_sourceline();
@@ -1710,4 +1714,6 @@ Init_eval(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/eval.c#L1714
     rb_define_global_function("untrace_var", rb_f_untrace_var, -1);	/* in variable.c */
 
     rb_vm_register_special_exception(ruby_error_reenter, rb_eFatal, "exception reentered");
+
+    id_cause = rb_intern_const("cause");
 }
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 54674)
+++ ruby_2_2/version.h	(revision 54675)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #define RUBY_VERSION "2.2.5"
 #define RUBY_RELEASE_DATE "2016-04-22"
-#define RUBY_PATCHLEVEL 296
+#define RUBY_PATCHLEVEL 297
 
 #define RUBY_RELEASE_YEAR 2016
 #define RUBY_RELEASE_MONTH 4
Index: ruby_2_2/test/ruby/test_exception.rb
===================================================================
--- ruby_2_2/test/ruby/test_exception.rb	(revision 54674)
+++ ruby_2_2/test/ruby/test_exception.rb	(revision 54675)
@@ -618,6 +618,41 @@ end.join https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_exception.rb#L618
     assert_not_same(e, e.cause, "#{msg}: should not be recursive")
   end
 
+  def test_cause_raised_in_rescue
+    e = assert_raise_with_message(RuntimeError, 'b') {
+      begin
+        raise 'a'
+      rescue => a
+        begin
+          raise 'b'
+        rescue => b
+          begin
+            raise 'c'
+          rescue
+            raise b
+          end
+        end
+      end
+    }
+    assert_equal('a', e.cause.message, 'cause should not be overwritten by reraise')
+  end
+
+  def test_cause_at_raised
+    e = assert_raise_with_message(RuntimeError, 'b') {
+      begin
+        raise 'a'
+      rescue => a
+        b = RuntimeError.new('b')
+        begin
+          raise 'c'
+        rescue
+          raise b
+        end
+      end
+    }
+    assert_equal('c', e.cause.message, 'cause should be the exception at raised')
+  end
+
   def test_raise_with_cause
     msg = "[Feature #8257]"
     cause = ArgumentError.new("foobar")
@@ -632,6 +667,25 @@ end.join https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_exception.rb#L667
     end
   end
 
+  def test_raise_with_cause_in_rescue
+    e = assert_raise_with_message(RuntimeError, 'b') {
+      begin
+        raise 'a'
+      rescue => a
+        begin
+          raise 'b'
+        rescue => b
+          begin
+            raise 'c'
+          rescue
+            raise b, cause: ArgumentError.new('d')
+          end
+        end
+      end
+    }
+    assert_equal('d', e.cause.message, 'cause option should be honored always')
+  end
+
   def test_unknown_option
     bug = '[ruby-core:63203] [Feature #8257] should pass unknown options'
 
Index: ruby_2_2/ChangeLog
===================================================================
--- ruby_2_2/ChangeLog	(revision 54674)
+++ ruby_2_2/ChangeLog	(revision 54675)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1
+Fri Apr 22 14:34:27 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* eval.c (setup_exception): set the cause only if it is explicitly
+	  given or not set yet.  [Bug #12068]
+
 Fri Apr 22 14:13:28 2016  sorah (Shota Fukumori)  <her@s...>
 
 	* lib/forwardable.rb: Convert given accessors to String.

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r53819,53822


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

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