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

ruby-changes:52111

From: nagachika <ko1@a...>
Date: Sun, 12 Aug 2018 19:37:08 +0900 (JST)
Subject: [ruby-changes:52111] nagachika:r64319 (ruby_2_5): merge revision(s) 63133: [Backport #14566]

nagachika	2018-08-12 19:37:03 +0900 (Sun, 12 Aug 2018)

  New Revision: 64319

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

  Log:
    merge revision(s) 63133: [Backport #14566]
    
    eval_error.c: fix loop on exception in message
    
    * error.c (rb_get_message): accessor to the message.
    
    * eval_error.c (rb_ec_error_print): handle exceptions on fetching
      the message.  [Bug #14566]

  Modified directories:
    branches/ruby_2_5/
  Modified files:
    branches/ruby_2_5/error.c
    branches/ruby_2_5/eval_error.c
    branches/ruby_2_5/test/ruby/test_exception.rb
    branches/ruby_2_5/version.h
Index: ruby_2_5/version.h
===================================================================
--- ruby_2_5/version.h	(revision 64318)
+++ ruby_2_5/version.h	(revision 64319)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1
 #define RUBY_VERSION "2.5.2"
-#define RUBY_RELEASE_DATE "2018-08-05"
-#define RUBY_PATCHLEVEL 66
+#define RUBY_RELEASE_DATE "2018-08-12"
+#define RUBY_PATCHLEVEL 67
 
 #define RUBY_RELEASE_YEAR 2018
 #define RUBY_RELEASE_MONTH 8
-#define RUBY_RELEASE_DAY 5
+#define RUBY_RELEASE_DAY 12
 
 #include "ruby/version.h"
 
Index: ruby_2_5/error.c
===================================================================
--- ruby_2_5/error.c	(revision 64318)
+++ ruby_2_5/error.c	(revision 64319)
@@ -960,7 +960,16 @@ exc_to_s(VALUE exc) https://github.com/ruby/ruby/blob/trunk/ruby_2_5/error.c#L960
 }
 
 /* FIXME: Include eval_error.c */
-void rb_error_write(VALUE errinfo, VALUE errat, VALUE str, VALUE highlight, VALUE reverse);
+void rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlight, VALUE reverse);
+
+VALUE
+rb_get_message(VALUE exc)
+{
+    VALUE e = rb_check_funcall(exc, id_message, 0, 0);
+    if (e == Qundef) return Qnil;
+    if (!RB_TYPE_P(e, T_STRING)) e = rb_check_string_type(e);
+    return e;
+}
 
 /*
  * call-seq:
@@ -995,7 +1004,7 @@ exc_s_to_tty_p(VALUE self) https://github.com/ruby/ruby/blob/trunk/ruby_2_5/error.c#L1004
 static VALUE
 exc_full_message(int argc, VALUE *argv, VALUE exc)
 {
-    VALUE opt, str, errat;
+    VALUE opt, str, emesg, errat;
     enum {kw_highlight, kw_order, kw_max_};
     static ID kw[kw_max_];
     VALUE args[kw_max_] = {Qnil, Qnil};
@@ -1031,8 +1040,9 @@ exc_full_message(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ruby_2_5/error.c#L1040
     }
     str = rb_str_new2("");
     errat = rb_get_backtrace(exc);
+    emesg = rb_get_message(exc);
 
-    rb_error_write(exc, errat, str, args[kw_highlight], args[kw_order]);
+    rb_error_write(exc, emesg, errat, str, args[kw_highlight], args[kw_order]);
     return str;
 }
 
Index: ruby_2_5/eval_error.c
===================================================================
--- ruby_2_5/eval_error.c	(revision 64318)
+++ ruby_2_5/eval_error.c	(revision 64319)
@@ -192,9 +192,9 @@ print_backtrace(const VALUE eclass, cons https://github.com/ruby/ruby/blob/trunk/ruby_2_5/eval_error.c#L192
 }
 
 void
-rb_error_write(VALUE errinfo, VALUE errat, VALUE str, VALUE highlight, VALUE reverse)
+rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlight, VALUE reverse)
 {
-    volatile VALUE eclass = Qundef, emesg = Qundef;
+    volatile VALUE eclass;
 
     if (NIL_P(errinfo))
 	return;
@@ -202,13 +202,7 @@ rb_error_write(VALUE errinfo, VALUE erra https://github.com/ruby/ruby/blob/trunk/ruby_2_5/eval_error.c#L202
     if (errat == Qundef) {
 	errat = Qnil;
     }
-    if ((eclass = CLASS_OF(errinfo)) != Qundef) {
-	VALUE e = rb_check_funcall(errinfo, rb_intern("message"), 0, 0);
-	if (e != Qundef) {
-	    if (!RB_TYPE_P(e, T_STRING)) e = rb_check_string_type(e);
-	    emesg = e;
-	}
-    }
+    eclass = CLASS_OF(errinfo);
     if (NIL_P(reverse) || NIL_P(highlight)) {
 	VALUE tty = (VALUE)rb_stderr_tty_p();
 	if (NIL_P(reverse)) reverse = tty;
@@ -240,11 +234,14 @@ rb_error_write(VALUE errinfo, VALUE erra https://github.com/ruby/ruby/blob/trunk/ruby_2_5/eval_error.c#L234
     }
 }
 
+VALUE rb_get_message(VALUE exc);
+
 void
 rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo)
 {
     volatile int raised_flag = ec->raised_flag;
     volatile VALUE errat;
+    volatile VALUE emesg = Qundef;
 
     if (NIL_P(errinfo))
 	return;
@@ -254,8 +251,12 @@ rb_ec_error_print(rb_execution_context_t https://github.com/ruby/ruby/blob/trunk/ruby_2_5/eval_error.c#L251
     if (EC_EXEC_TAG() == TAG_NONE) {
 	errat = rb_get_backtrace(errinfo);
     }
+    if (emesg == Qundef) {
+	emesg = Qnil;
+	emesg = rb_get_message(errinfo);
+    }
 
-    rb_error_write(errinfo, errat, Qnil, Qnil, Qnil);
+    rb_error_write(errinfo, emesg, errat, Qnil, Qnil, Qnil);
 
     EC_POP_TAG();
     ec->errinfo = errinfo;
Index: ruby_2_5/test/ruby/test_exception.rb
===================================================================
--- ruby_2_5/test/ruby/test_exception.rb	(revision 64318)
+++ ruby_2_5/test/ruby/test_exception.rb	(revision 64319)
@@ -1157,4 +1157,15 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/ruby/test_exception.rb#L1157
     message = e.full_message(highlight: true)
     assert_match(/\e/, message)
   end
+
+  def test_exception_in_message
+    code = "#{<<~"begin;"}\n#{<<~'end;'}"
+    begin;
+      class Bug14566 < StandardError
+        def message; raise self.class; end
+      end
+      raise Bug14566
+    end;
+    assert_in_out_err([], code, [], /Bug14566/, success: false, timeout: 1)
+  end
 end
Index: ruby_2_5
===================================================================
--- ruby_2_5	(revision 64318)
+++ ruby_2_5	(revision 64319)

Property changes on: ruby_2_5
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r63133

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

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