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

ruby-changes:21979

From: nagachika <ko1@a...>
Date: Tue, 13 Dec 2011 23:50:23 +0900 (JST)
Subject: [ruby-changes:21979] nagachika:r34028 (trunk): * error.c (name_err_mesg_to_str): clear rb_thread_t::errinfo when

nagachika	2011-12-13 23:50:12 +0900 (Tue, 13 Dec 2011)

  New Revision: 34028

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

  Log:
    * error.c (name_err_mesg_to_str): clear rb_thread_t::errinfo when
      ignore exception under rb_protect().
    
    * test/ruby/test_exception.rb (test_exception_in_name_error_to_str):
      add a corresponding test.

  Modified files:
    trunk/ChangeLog
    trunk/error.c
    trunk/test/ruby/test_exception.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34027)
+++ ChangeLog	(revision 34028)
@@ -1,3 +1,11 @@
+Tue Dec 13 23:43:48 2011  CHIKANAGA Tomoyuki  <nagachika00@g...>
+
+	* error.c (name_err_mesg_to_str): clear rb_thread_t::errinfo when
+	  ignore exception under rb_protect().
+
+	* test/ruby/test_exception.rb (test_exception_in_name_error_to_str):
+	  add a corresponding test.
+
 Tue Dec 13 16:13:29 2011  Nobuyoshi Nakada  <nobu@r...>
 
 	* load.c (load_unlock): all threads requiring one file should
Index: error.c
===================================================================
--- error.c	(revision 34027)
+++ error.c	(revision 34028)
@@ -1012,6 +1012,7 @@
     else {
 	const char *desc = 0;
 	VALUE d = 0, args[NAME_ERR_MESG_COUNT];
+	int state = 0;
 
 	obj = ptr[1];
 	switch (TYPE(obj)) {
@@ -1025,7 +1026,9 @@
 	    desc = "false";
 	    break;
 	  default:
-	    d = rb_protect(rb_inspect, obj, 0);
+	    d = rb_protect(rb_inspect, obj, &state);
+	    if (state)
+		rb_set_errinfo(Qnil);
 	    if (NIL_P(d) || RSTRING_LEN(d) > 65) {
 		d = rb_any_to_s(obj);
 	    }
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 34027)
+++ test/ruby/test_exception.rb	(revision 34028)
@@ -1,4 +1,5 @@
 require 'test/unit'
+require 'tempfile'
 require_relative 'envutil'
 
 class TestException < Test::Unit::TestCase
@@ -363,4 +364,20 @@
     assert_equal(false, efs.success?, bug5728)
     assert_equal("msg", efs.message, bug5728)
   end
+
+  def test_exception_in_name_error_to_str
+    bug5575 = '[ruby-core:41612]'
+    t = Tempfile.new(["test_exception_in_name_error_to_str", ".rb"])
+    t.puts <<-EOC
+      begin
+        BasicObject.new.inspect
+      rescue
+        $!.inspect
+      end
+    EOC
+    t.close
+    assert_nothing_raised(NameError, bug5575) do
+      load(t.path)
+    end
+  end
 end

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

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