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

ruby-changes:36491

From: nobu <ko1@a...>
Date: Wed, 26 Nov 2014 03:44:23 +0900 (JST)
Subject: [ruby-changes:36491] nobu:r48573 (trunk): vm_method.c: preserve encodings

nobu	2014-11-26 03:44:12 +0900 (Wed, 26 Nov 2014)

  New Revision: 48573

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

  Log:
    vm_method.c: preserve encodings
    
    * vm_method.c (rb_method_entry_make): preserve encodings of
      constant names in warning messages.

  Modified files:
    trunk/test/ruby/test_const.rb
    trunk/vm_method.c
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 48572)
+++ vm_method.c	(revision 48573)
@@ -322,7 +322,7 @@ rb_method_entry_make(VALUE klass, ID mid https://github.com/ruby/ruby/blob/trunk/vm_method.c#L322
 	    old_def->type != VM_METHOD_TYPE_ZSUPER) {
 	    rb_iseq_t *iseq = 0;
 
-	    rb_warning("method redefined; discarding old %s", rb_id2name(mid));
+	    rb_warning("method redefined; discarding old %"PRIsVALUE, rb_id2str(mid));
 	    switch (old_def->type) {
 	      case VM_METHOD_TYPE_ISEQ:
 		iseq = old_def->body.iseq;
@@ -336,8 +336,8 @@ rb_method_entry_make(VALUE klass, ID mid https://github.com/ruby/ruby/blob/trunk/vm_method.c#L336
 	    if (iseq && !NIL_P(iseq->location.path)) {
 		int line = iseq->line_info_table ? FIX2INT(rb_iseq_first_lineno(iseq->self)) : 0;
 		rb_compile_warning(RSTRING_PTR(iseq->location.path), line,
-				   "previous definition of %s was here",
-				   rb_id2name(old_def->original_id));
+				   "previous definition of %"PRIsVALUE" was here",
+				   rb_id2str(old_def->original_id));
 	    }
 	}
 
@@ -762,8 +762,8 @@ remove_method(VALUE klass, ID mid) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L762
     if (!st_lookup(RCLASS_M_TBL(klass), mid, &data) ||
 	!(me = (rb_method_entry_t *)data) ||
 	(!me->def || me->def->type == VM_METHOD_TYPE_UNDEF)) {
-	rb_name_error(mid, "method `%s' not defined in %s",
-		      rb_id2name(mid), rb_class2name(klass));
+	rb_name_error(mid, "method `%"PRIsVALUE"' not defined in %"PRIsVALUE,
+		      rb_id2str(mid), rb_class_path(klass));
     }
     key = (st_data_t)mid;
     st_delete(RCLASS_M_TBL(klass), &key, &data);
Index: test/ruby/test_const.rb
===================================================================
--- test/ruby/test_const.rb	(revision 48572)
+++ test/ruby/test_const.rb	(revision 48573)
@@ -49,11 +49,15 @@ class TestConst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_const.rb#L49
 
   def test_redefinition
     c = Class.new
-    c.const_set(:X, 1)
-    assert_output(nil, <<-WARNING) {c.const_set(:X, 2)}
-#{__FILE__}:#{__LINE__-1}: warning: already initialized constant #{c}::X
-#{__FILE__}:#{__LINE__-3}: warning: previous definition of X was here
+    name = "X\u{5b9a 6570}"
+    c.const_set(name, 1)
+    prev_line = __LINE__ - 1
+    EnvUtil.with_default_internal(Encoding::UTF_8) do
+      assert_output(nil, <<-WARNING) {c.const_set(name, 2)}
+#{__FILE__}:#{__LINE__-1}: warning: already initialized constant #{c}::#{name}
+#{__FILE__}:#{prev_line}: warning: previous definition of #{name} was here
 WARNING
+    end
     code = <<-PRE
 olderr = $stderr.dup
 $stderr.reopen(File::NULL, "wb")

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

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