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

ruby-changes:45064

From: nobu <ko1@a...>
Date: Wed, 21 Dec 2016 20:12:45 +0900 (JST)
Subject: [ruby-changes:45064] nobu:r57137 (trunk): eval.c: fix circular cause

nobu	2016-12-21 20:12:39 +0900 (Wed, 21 Dec 2016)

  New Revision: 57137

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

  Log:
    eval.c: fix circular cause
    
    * eval.c (exc_setup_cause): always set cause of cause to get rid
      of circular references.  [ruby-core:78688] [Bug #13043]

  Modified files:
    trunk/eval.c
    trunk/test/ruby/test_exception.rb
Index: eval.c
===================================================================
--- eval.c	(revision 57136)
+++ eval.c	(revision 57137)
@@ -457,6 +457,9 @@ exc_setup_cause(VALUE exc, VALUE cause) https://github.com/ruby/ruby/blob/trunk/eval.c#L457
 #endif
     if (!NIL_P(cause) && cause != exc) {
 	rb_ivar_set(exc, id_cause, cause);
+	if (!rb_ivar_defined(cause, id_cause)) {
+	    rb_ivar_set(cause, id_cause, Qnil);
+	}
     }
     return exc;
 }
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 57136)
+++ test/ruby/test_exception.rb	(revision 57137)
@@ -777,6 +777,26 @@ end.join https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L777
     assert_equal({}, e.arg, bug)
   end
 
+  def test_circular_cause
+    bug13043 = '[ruby-core:78688] [Bug #13043]'
+    begin
+      begin
+        raise "error 1"
+      ensure
+        orig_error = $!
+        begin
+          raise "error 2"
+        rescue => err
+          raise orig_error
+        end
+      end
+    rescue => x
+    end
+    assert_equal(orig_error, x)
+    assert_equal(orig_error, err.cause)
+    assert_nil(orig_error.cause, bug13043)
+  end
+
   def test_anonymous_message
     assert_in_out_err([], "raise Class.new(RuntimeError), 'foo'", [], /foo\n/)
   end

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

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