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

ruby-changes:35552

From: nobu <ko1@a...>
Date: Fri, 19 Sep 2014 10:46:50 +0900 (JST)
Subject: [ruby-changes:35552] nobu:r47634 (trunk): error.c: preserve encoding

nobu	2014-09-19 10:46:42 +0900 (Fri, 19 Sep 2014)

  New Revision: 47634

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

  Log:
    error.c: preserve encoding
    
    * error.c (rb_error_frozen_object): preserve encoding of class
      name in error message.

  Modified files:
    trunk/error.c
    trunk/include/ruby/intern.h
    trunk/test/ruby/test_object.rb
Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 47633)
+++ include/ruby/intern.h	(revision 47634)
@@ -255,13 +255,14 @@ PRINTF_ARGS(void rb_compile_error(const https://github.com/ruby/ruby/blob/trunk/include/ruby/intern.h#L255
 PRINTF_ARGS(void rb_compile_error_with_enc(const char*, int, void *, const char*, ...), 4, 5);
 PRINTF_ARGS(void rb_compile_error_append(const char*, ...), 1, 2);
 NORETURN(void rb_error_frozen(const char*));
+NORETURN(void rb_error_frozen_object(VALUE));
 void rb_error_untrusted(VALUE);
 void rb_check_frozen(VALUE);
 void rb_check_trusted(VALUE);
 #define rb_check_frozen_internal(obj) do { \
 	VALUE frozen_obj = (obj); \
 	if (OBJ_FROZEN(frozen_obj)) { \
-	    rb_error_frozen(rb_obj_classname(frozen_obj)); \
+	    rb_error_frozen_object(frozen_obj); \
 	} \
     } while (0)
 #define rb_check_trusted_internal(obj) ((void) 0)
Index: error.c
===================================================================
--- error.c	(revision 47633)
+++ error.c	(revision 47634)
@@ -2129,6 +2129,13 @@ rb_error_frozen(const char *what) https://github.com/ruby/ruby/blob/trunk/error.c#L2129
     rb_raise(rb_eRuntimeError, "can't modify frozen %s", what);
 }
 
+void
+rb_error_frozen_object(VALUE frozen_obj)
+{
+    rb_raise(rb_eRuntimeError, "can't modify frozen %"PRIsVALUE,
+	     CLASS_OF(frozen_obj));
+}
+
 #undef rb_check_frozen
 void
 rb_check_frozen(VALUE obj)
Index: test/ruby/test_object.rb
===================================================================
--- test/ruby/test_object.rb	(revision 47633)
+++ test/ruby/test_object.rb	(revision 47634)
@@ -68,6 +68,17 @@ class TestObject < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_object.rb#L68
     assert_equal(true, nil.frozen?)
   end
 
+  def test_frozen_error_message
+    name = "C\u{30c6 30b9 30c8}"
+    klass = EnvUtil.labeled_class(name) {
+      attr_accessor :foo
+    }
+    obj = klass.new.freeze
+    assert_raise_with_message(RuntimeError, /#{name}/) {
+      obj.foo = 1
+    }
+  end
+
   def test_nil_to_f
     assert_equal(0.0, nil.to_f)
   end

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

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