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

ruby-changes:33101

From: nobu <ko1@a...>
Date: Wed, 26 Feb 2014 13:26:33 +0900 (JST)
Subject: [ruby-changes:33101] nobu:r45180 (trunk): eval.c: preserve errinfo

nobu	2014-02-26 13:26:23 +0900 (Wed, 26 Feb 2014)

  New Revision: 45180

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45180

  Log:
    eval.c: preserve errinfo
    
    * eval.c (setup_exception): preserve errinfo across calling #to_s
      method on the exception.  [ruby-core:61091] [Bug #9568]

  Modified files:
    trunk/ChangeLog
    trunk/eval.c
    trunk/test/ruby/test_exception.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45179)
+++ ChangeLog	(revision 45180)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Feb 26 13:26:21 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* eval.c (setup_exception): preserve errinfo across calling #to_s
+	  method on the exception.  [ruby-core:61091] [Bug #9568]
+
 Wed Feb 26 01:29:27 2014  NARUSE, Yui  <naruse@r...>
 
 	* string.c (sym_find): Add Symbol.find(str), which returns whether given
Index: eval.c
===================================================================
--- eval.c	(revision 45179)
+++ eval.c	(revision 45180)
@@ -511,9 +511,12 @@ setup_exception(rb_thread_t *th, int tag https://github.com/ruby/ruby/blob/trunk/eval.c#L511
 	!rb_obj_is_kind_of(e, rb_eSystemExit)) {
 	int status;
 
+	mesg = e;
 	PUSH_TAG();
 	if ((status = EXEC_TAG()) == 0) {
+	    th->errinfo = Qnil;
 	    e = rb_obj_as_string(e);
+	    th->errinfo = mesg;
 	    if (file && line) {
 		warn_printf("Exception `%s' at %s:%d - %"PRIsVALUE"\n",
 			    rb_obj_classname(th->errinfo), file, line, e);
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 45179)
+++ test/ruby/test_exception.rb	(revision 45180)
@@ -78,6 +78,28 @@ class TestException < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L78
     assert(!bad)
   end
 
+  def test_errinfo_in_debug
+    bug9568 = EnvUtil.labeled_class("[ruby-core:61091] [Bug #9568]", RuntimeError) do
+      def to_s
+        require '\0'
+      rescue LoadError
+        self.class.to_s
+      end
+    end
+
+    err = EnvUtil.verbose_warning do
+      assert_raise(bug9568) do
+        $DEBUG, debug = true, $DEBUG
+        begin
+          raise bug9568
+        ensure
+          $DEBUG = debug
+        end
+      end
+    end
+    assert_include(err, bug9568.to_s)
+  end
+
   def test_break_ensure
     bad = true
     while true

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

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