ruby-changes:30430
From: nobu <ko1@a...>
Date: Sun, 11 Aug 2013 15:11:24 +0900 (JST)
Subject: [ruby-changes:30430] nobu:r42509 (trunk): parse.y: non-local/const attrset
nobu 2013-08-11 15:11:17 +0900 (Sun, 11 Aug 2013) New Revision: 42509 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42509 Log: parse.y: non-local/const attrset * parse.y (rb_enc_symname_type): allow ID_ATTRSET for ID_INSTANCE, ID_GLOBAL, ID_CLASS, ID_JUNK too. [Bug #8756] Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ruby/test_struct.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42508) +++ ChangeLog (revision 42509) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Aug 11 15:10:40 2013 Nobuyoshi Nakada <nobu@r...> + + * parse.y (rb_enc_symname_type): allow ID_ATTRSET for ID_INSTANCE, + ID_GLOBAL, ID_CLASS, ID_JUNK too. [Bug #8756] + Sun Aug 11 13:17:00 2013 Charlie Somerville <charliesome@r...> * include/ruby/encoding.h: Reduce ENCODING_INLINE_MAX to 127 as this Index: parse.y =================================================================== --- parse.y (revision 42508) +++ parse.y (revision 42509) @@ -10182,8 +10182,11 @@ rb_enc_symname_p(const char *name, rb_en https://github.com/ruby/ruby/blob/trunk/parse.y#L10182 return rb_enc_symname2_p(name, strlen(name), enc); } +#define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST)) +#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<ID_SCOPE_MASK) & ~(1U<<ID_ATTRSET)) + static int -rb_enc_symname_type(const char *name, long len, rb_encoding *enc) +rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_atttset) { const char *m = name; const char *e = m + len; @@ -10267,7 +10270,7 @@ rb_enc_symname_type(const char *name, lo https://github.com/ruby/ruby/blob/trunk/parse.y#L10270 ++m; break; case '=': - if (type != ID_CONST && type != ID_LOCAL) return -1; + if (!(allowed_atttset & (1U << type))) return -1; type = ID_ATTRSET; ++m; break; @@ -10280,15 +10283,15 @@ rb_enc_symname_type(const char *name, lo https://github.com/ruby/ruby/blob/trunk/parse.y#L10283 int rb_enc_symname2_p(const char *name, long len, rb_encoding *enc) { - return rb_enc_symname_type(name, len, enc) != -1; + return rb_enc_symname_type(name, len, enc, IDSET_ATTRSET_FOR_SYNTAX) != -1; } static int -rb_str_symname_type(VALUE name) +rb_str_symname_type(VALUE name, unsigned int allowed_atttset) { const char *ptr = StringValuePtr(name); long len = RSTRING_LEN(name); - int type = rb_enc_symname_type(ptr, len, rb_enc_get(name)); + int type = rb_enc_symname_type(ptr, len, rb_enc_get(name), allowed_atttset); RB_GC_GUARD(name); return type; } @@ -10719,43 +10722,43 @@ rb_check_id_cstr(const char *ptr, long l https://github.com/ruby/ruby/blob/trunk/parse.y#L10722 int rb_is_const_name(VALUE name) { - return rb_str_symname_type(name) == ID_CONST; + return rb_str_symname_type(name, 0) == ID_CONST; } int rb_is_class_name(VALUE name) { - return rb_str_symname_type(name) == ID_CLASS; + return rb_str_symname_type(name, 0) == ID_CLASS; } int rb_is_global_name(VALUE name) { - return rb_str_symname_type(name) == ID_GLOBAL; + return rb_str_symname_type(name, 0) == ID_GLOBAL; } int rb_is_instance_name(VALUE name) { - return rb_str_symname_type(name) == ID_INSTANCE; + return rb_str_symname_type(name, 0) == ID_INSTANCE; } int rb_is_attrset_name(VALUE name) { - return rb_str_symname_type(name) == ID_ATTRSET; + return rb_str_symname_type(name, IDSET_ATTRSET_FOR_INTERN) == ID_ATTRSET; } int rb_is_local_name(VALUE name) { - return rb_str_symname_type(name) == ID_LOCAL; + return rb_str_symname_type(name, 0) == ID_LOCAL; } int rb_is_method_name(VALUE name) { - switch (rb_str_symname_type(name)) { + switch (rb_str_symname_type(name, 0)) { case ID_LOCAL: case ID_ATTRSET: case ID_JUNK: return TRUE; } @@ -10765,7 +10768,7 @@ rb_is_method_name(VALUE name) https://github.com/ruby/ruby/blob/trunk/parse.y#L10768 int rb_is_junk_name(VALUE name) { - return rb_str_symname_type(name) == -1; + return rb_str_symname_type(name, IDSET_ATTRSET_FOR_SYNTAX) == -1; } #endif /* !RIPPER */ Index: test/ruby/test_struct.rb =================================================================== --- test/ruby/test_struct.rb (revision 42508) +++ test/ruby/test_struct.rb (revision 42509) @@ -131,7 +131,15 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_struct.rb#L131 klass = Struct.new(:@a) o = klass.new(1) + assert_equal(1, o.__send__(:@a)) assert_equal("#<struct :@a=1>", o.inspect) + o.__send__(:"@a=", 2) + assert_equal(2, o.__send__(:@a)) + assert_equal("#<struct :@a=2>", o.inspect) + o.__send__("@a=", 3) + assert_equal(3, o.__send__(:@a)) + assert_equal("#<struct :@a=3>", o.inspect) + methods = klass.instance_methods(false) assert_equal([:@a, :"@a="].inspect, methods.inspect, '[Bug #8756]') assert_include(methods, :@a) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/