ruby-changes:32889
From: nagachika <ko1@a...>
Date: Sat, 15 Feb 2014 16:18:32 +0900 (JST)
Subject: [ruby-changes:32889] nagachika:r44968 (ruby_2_0_0): merge revision(s) r40101:
nagachika 2014-02-15 16:18:22 +0900 (Sat, 15 Feb 2014) New Revision: 44968 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44968 Log: merge revision(s) r40101: * struct.c (make_struct): avoid inadvertent symbol creation. (rb_struct_aref): ditto. (rb_struct_aset): ditto. Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/struct.c branches/ruby_2_0_0/test/-ext-/symbol/test_inadvertent_creation.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 44967) +++ ruby_2_0_0/ChangeLog (revision 44968) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Sat Feb 15 16:08:26 2014 Nobuyoshi Nakada <nobu@r...> + + * struct.c (make_struct): avoid inadvertent symbol creation. + (rb_struct_aref): ditto. + (rb_struct_aset): ditto. + Sat Feb 15 15:32:46 2014 Shugo Maeda <shugo@r...> * vm_insnhelper.c (vm_call_method): should check ci->me->flag of Index: ruby_2_0_0/struct.c =================================================================== --- ruby_2_0_0/struct.c (revision 44967) +++ ruby_2_0_0/struct.c (revision 44968) @@ -187,10 +187,11 @@ make_struct(VALUE name, VALUE members, V https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/struct.c#L187 else { /* old style: should we warn? */ name = rb_str_to_str(name); - id = rb_to_id(name); - if (!rb_is_const_id(id)) { - rb_name_error(id, "identifier %s needs to be constant", StringValuePtr(name)); + if (!rb_is_const_name(name)) { + rb_name_error_str(name, "identifier %"PRIsVALUE" needs to be constant", + QUOTE(name)); } + id = rb_to_id(name); if (rb_const_defined_at(klass, id)) { rb_warn("redefining constant Struct::%s", StringValuePtr(name)); rb_mod_remove_const(klass, ID2SYM(id)); @@ -672,8 +673,16 @@ rb_struct_aref(VALUE s, VALUE idx) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/struct.c#L673 { long i; - if (RB_TYPE_P(idx, T_STRING) || RB_TYPE_P(idx, T_SYMBOL)) { - return rb_struct_aref_id(s, rb_to_id(idx)); + if (RB_TYPE_P(idx, T_SYMBOL)) { + return rb_struct_aref_id(s, SYM2ID(idx)); + } + else if (RB_TYPE_P(idx, T_STRING)) { + ID id = rb_check_id(&idx); + if (!id) { + rb_name_error_str(idx, "no member '%"PRIsVALUE"' in struct", + QUOTE(idx)); + } + return rb_struct_aref_id(s, id); } i = NUM2LONG(idx); @@ -739,8 +748,16 @@ rb_struct_aset(VALUE s, VALUE idx, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/struct.c#L748 { long i; - if (RB_TYPE_P(idx, T_STRING) || RB_TYPE_P(idx, T_SYMBOL)) { - return rb_struct_aset_id(s, rb_to_id(idx), val); + if (RB_TYPE_P(idx, T_SYMBOL)) { + return rb_struct_aset_id(s, SYM2ID(idx), val); + } + if (RB_TYPE_P(idx, T_STRING)) { + ID id = rb_check_id(&idx); + if (!id) { + rb_name_error_str(idx, "no member '%"PRIsVALUE"' in struct", + QUOTE(idx)); + } + return rb_struct_aset_id(s, id, val); } i = NUM2LONG(idx); Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 44967) +++ ruby_2_0_0/version.h (revision 44968) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2014-02-15" -#define RUBY_PATCHLEVEL 403 +#define RUBY_PATCHLEVEL 404 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 2 Index: ruby_2_0_0/test/-ext-/symbol/test_inadvertent_creation.rb =================================================================== --- ruby_2_0_0/test/-ext-/symbol/test_inadvertent_creation.rb (revision 44967) +++ ruby_2_0_0/test/-ext-/symbol/test_inadvertent_creation.rb (revision 44968) @@ -159,5 +159,25 @@ module Test_Symbol https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/-ext-/symbol/test_inadvertent_creation.rb#L159 assert_equal(name, e.name) assert_equal([Feature5112], e.args) end + + def test_struct_new + name = noninterned_name + assert_raise(NameError) {Struct.new(name)} + assert_not_send([Bug::Symbol, :interned?, name]) + end + + def test_struct_aref + s = Struct.new(:foo).new + name = noninterned_name + assert_raise(NameError) {s[name]} + assert_not_send([Bug::Symbol, :interned?, name]) + end + + def test_struct_aset + s = Struct.new(:foo).new + name = noninterned_name + assert_raise(NameError) {s[name] = true} + assert_not_send([Bug::Symbol, :interned?, name]) + end end end Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r40101 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/