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

ruby-changes:51210

From: nobu <ko1@a...>
Date: Mon, 14 May 2018 17:33:20 +0900 (JST)
Subject: [ruby-changes:51210] nobu:r63417 (trunk): error.c: check redefined backtrace result

nobu	2018-05-14 17:33:14 +0900 (Mon, 14 May 2018)

  New Revision: 63417

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

  Log:
    error.c: check redefined backtrace result
    
    * error.c (rb_get_backtrace): check the result of `backtrace` even
      if the method is redefined.  [ruby-core:87013] [Bug #14756]

  Modified files:
    trunk/error.c
    trunk/test/ruby/test_exception.rb
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 63416)
+++ test/ruby/test_exception.rb	(revision 63417)
@@ -1236,6 +1236,16 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1236
         raise RuntimeError, "hello"
       }
     end;
+
+    error_class = Class.new(StandardError) do
+      def backtrace; :backtrace; end
+    end
+    begin
+      raise error_class
+    rescue error_class => e
+      assert_raise(TypeError) {$@}
+      assert_raise(TypeError) {e.full_message}
+    end
   end
 
   def test_backtrace_in_eval
Index: error.c
===================================================================
--- error.c	(revision 63416)
+++ error.c	(revision 63417)
@@ -1162,19 +1162,21 @@ VALUE https://github.com/ruby/ruby/blob/trunk/error.c#L1162
 rb_get_backtrace(VALUE exc)
 {
     ID mid = id_backtrace;
+    VALUE info;
     if (rb_method_basic_definition_p(CLASS_OF(exc), id_backtrace)) {
-	VALUE info, klass = rb_eException;
+	VALUE klass = rb_eException;
 	rb_execution_context_t *ec = GET_EC();
 	if (NIL_P(exc))
 	    return Qnil;
 	EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, exc, mid, mid, klass, Qundef);
 	info = exc_backtrace(exc);
 	EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, exc, mid, mid, klass, info);
-	if (NIL_P(info))
-	    return Qnil;
-	return rb_check_backtrace(info);
     }
-    return rb_funcallv(exc, mid, 0, 0);
+    else {
+	info = rb_funcallv(exc, mid, 0, 0);
+    }
+    if (NIL_P(info)) return Qnil;
+    return rb_check_backtrace(info);
 }
 
 /*

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

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