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

ruby-changes:62370

From: nagachika <ko1@a...>
Date: Thu, 23 Jul 2020 12:13:42 +0900 (JST)
Subject: [ruby-changes:62370] 27fa1c61b7 (ruby_2_7): merge revision(s) 579645d9f870fa4116dcd3200bbbb6e2c0b7f400: [Backport #17033]

https://git.ruby-lang.org/ruby.git/commit/?id=27fa1c61b7

From 27fa1c61b78c1685ccf9ac203a95cfa9041d618f Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Thu, 23 Jul 2020 12:13:30 +0900
Subject: merge revision(s) 579645d9f870fa4116dcd3200bbbb6e2c0b7f400: [Backport
 #17033]

	Fixed infinite loop at error in printing cause [Bug #17033]

diff --git a/eval_error.c b/eval_error.c
index 847072a..9d2de6d 100644
--- a/eval_error.c
+++ b/eval_error.c
@@ -348,6 +348,7 @@ rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo) https://github.com/ruby/ruby/blob/trunk/eval_error.c#L348
     volatile uint8_t raised_flag = ec->raised_flag;
     volatile VALUE errat = Qundef;
     volatile VALUE emesg = Qundef;
+    volatile bool written = false;
 
     if (NIL_P(errinfo))
 	return;
@@ -362,7 +363,10 @@ rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo) https://github.com/ruby/ruby/blob/trunk/eval_error.c#L363
 	emesg = rb_get_message(errinfo);
     }
 
-    rb_error_write(errinfo, emesg, errat, Qnil, Qnil, Qnil);
+    if (!written) {
+        written = true;
+        rb_error_write(errinfo, emesg, errat, Qnil, Qnil, Qnil);
+    }
 
     EC_POP_TAG();
     ec->errinfo = errinfo;
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 79ac11a..69bf7eb 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -824,6 +824,26 @@ end.join https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L824
     }
   end
 
+  def test_cause_exception_in_cause_message
+    assert_in_out_err([], "#{<<~"begin;"}\n#{<<~'end;'}") do |outs, errs, status|
+      begin;
+        exc = Class.new(StandardError) do
+          def initialize(obj, cnt)
+            super(obj)
+            @errcnt = cnt
+          end
+          def to_s
+            return super if @errcnt <= 0
+            @errcnt -= 1
+            raise "xxx"
+          end
+        end.new("ok", 10)
+        raise "[Bug #17033]", cause: exc
+      end;
+      assert_equal(1, errs.count {|m| m.include?("[Bug #17033]")}, proc {errs.pretty_inspect})
+    end
+  end
+
   def test_anonymous_message
     assert_in_out_err([], "raise Class.new(RuntimeError), 'foo'", [], /foo\n/)
   end
diff --git a/version.h b/version.h
index 15007f2..bc61b57 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L2
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 1
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 100
+#define RUBY_PATCHLEVEL 101
 
 #define RUBY_RELEASE_YEAR 2020
 #define RUBY_RELEASE_MONTH 7
-- 
cgit v0.10.2


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

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