ruby-changes:31136
From: nobu <ko1@a...>
Date: Wed, 9 Oct 2013 18:03:15 +0900 (JST)
Subject: [ruby-changes:31136] nobu:r43215 (trunk): vm_method.c: preserve encoding
nobu 2013-10-09 18:03:07 +0900 (Wed, 09 Oct 2013) New Revision: 43215 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43215 Log: vm_method.c: preserve encoding * vm_method.c (rb_attr): preserve encoding of the attribute ID in error message. Modified files: trunk/ChangeLog trunk/test/ruby/test_module.rb trunk/vm_method.c Index: ChangeLog =================================================================== --- ChangeLog (revision 43214) +++ ChangeLog (revision 43215) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Oct 9 18:03:01 2013 Nobuyoshi Nakada <nobu@r...> + + * vm_method.c (rb_attr): preserve encoding of the attribute ID in + error message. + Wed Oct 9 17:40:16 2013 Nobuyoshi Nakada <nobu@r...> * string.c (rb_fstring): because of lazy sweep, str may be unmaked Index: vm_method.c =================================================================== --- vm_method.c (revision 43214) +++ vm_method.c (revision 43215) @@ -812,7 +812,6 @@ rb_method_boundp(VALUE klass, ID id, int https://github.com/ruby/ruby/blob/trunk/vm_method.c#L812 void rb_attr(VALUE klass, ID id, int read, int write, int ex) { - const char *name; ID attriv; VALUE aname; rb_method_flag_t noex; @@ -836,15 +835,13 @@ rb_attr(VALUE klass, ID id, int read, in https://github.com/ruby/ruby/blob/trunk/vm_method.c#L835 } if (!rb_is_local_id(id) && !rb_is_const_id(id)) { - rb_name_error(id, "invalid attribute name `%s'", rb_id2name(id)); + rb_name_error_str(id, "invalid attribute name `%"PRIsVALUE"'", QUOTE_ID(id)); } - name = rb_id2name(id); - if (!name) { + aname = rb_id2str(id); + if (NIL_P(aname)) { rb_raise(rb_eArgError, "argument needs to be symbol or string"); } - aname = rb_sprintf("@%s", name); - rb_enc_copy(aname, rb_id2str(id)); - attriv = rb_intern_str(aname); + attriv = rb_intern_str(rb_sprintf("@%"PRIsVALUE, aname)); if (read) { rb_add_method(klass, id, VM_METHOD_TYPE_IVAR, (void *)attriv, noex); } Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 43214) +++ test/ruby/test_module.rb (revision 43215) @@ -247,6 +247,7 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L247 "", ":", ["String::", "[Bug #7573]"], + "\u{3042}", ].each do |name, msg| expected = "wrong constant name %s" % name msg = "#{msg}#{': ' if msg}wrong constant name #{name.dump}" @@ -1653,11 +1654,12 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1654 end def test_invalid_attr - %w[ + %W[ foo? @foo @@foo $foo + \u{3042}$ ].each do |name| assert_raise_with_message(NameError, /#{Regexp.quote(name)}/) do Module.new { attr_accessor name.to_sym } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/