ruby-changes:35441
From: ko1 <ko1@a...>
Date: Thu, 11 Sep 2014 14:37:51 +0900 (JST)
Subject: [ruby-changes:35441] ko1:r47523 (trunk): * include/ruby/ruby.h: freeze nil/true/false.
ko1 2014-09-11 14:37:32 +0900 (Thu, 11 Sep 2014) New Revision: 47523 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47523 Log: * include/ruby/ruby.h: freeze nil/true/false. * gc.c (should_be_finalizable): check frozen after checkin FL_ABLE. * object.c (rb_obj_taint): check OBJ_TAINTABLE(obj). * object.c (rb_obj_freeze): remove immediate_frozen_tbl because all of immediate values are frozen. YAY! * object.c (rb_obj_frozen_p): ditto. * test/ruby/test_eval.rb: skip instance_variable_set for frozen objects. * test/ruby/test_weakmap.rb: check ArgumentError instead of RuntimeError. Modified files: trunk/ChangeLog trunk/gc.c trunk/include/ruby/ruby.h trunk/object.c trunk/test/ruby/test_eval.rb trunk/test/ruby/test_weakmap.rb Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 47522) +++ include/ruby/ruby.h (revision 47523) @@ -1126,7 +1126,7 @@ struct RStruct { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1126 (OBJ_TAINTABLE(x) && FL_ABLE(s)) ? \ RBASIC(x)->flags |= RBASIC(s)->flags & FL_TAINT : 0) -#define OBJ_FROZEN(x) (!!(FL_ABLE(x)?(RBASIC(x)->flags&(FL_FREEZE)):(FIXNUM_P(x)||FLONUM_P(x)||STATIC_SYM_P(x)))) +#define OBJ_FROZEN(x) (FL_ABLE(x) ? !!(RBASIC(x)->flags&FL_FREEZE) : 1) #define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE) #if USE_RGENGC Index: ChangeLog =================================================================== --- ChangeLog (revision 47522) +++ ChangeLog (revision 47523) @@ -1,3 +1,23 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Sep 11 14:31:57 2014 Koichi Sasada <ko1@a...> + + * include/ruby/ruby.h: freeze nil/true/false. + + * gc.c (should_be_finalizable): check frozen after checkin FL_ABLE. + + * object.c (rb_obj_taint): check + OBJ_TAINTABLE(obj). + + * object.c (rb_obj_freeze): remove immediate_frozen_tbl + because all of immediate values are frozen. YAY! + + * object.c (rb_obj_frozen_p): ditto. + + * test/ruby/test_eval.rb: skip instance_variable_set for + frozen objects. + + * test/ruby/test_weakmap.rb: check ArgumentError instead of + RuntimeError. + Thu Sep 11 10:03:16 2014 SHIBATA Hiroshi <shibata.hiroshi@g...> * lib/rdoc.rb, lib/rdoc, test/rdoc: Update to RDoc 4.2.0.alpha(21b241a) Index: object.c =================================================================== --- object.c (revision 47522) +++ object.c (revision 47523) @@ -980,7 +980,7 @@ rb_obj_tainted(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L980 VALUE rb_obj_taint(VALUE obj) { - if (!OBJ_TAINTED(obj)) { + if (!OBJ_TAINTED(obj) && OBJ_TAINTABLE(obj)) { rb_check_frozen(obj); OBJ_TAINT(obj); } @@ -1057,8 +1057,6 @@ rb_obj_infect(VALUE obj1, VALUE obj2) https://github.com/ruby/ruby/blob/trunk/object.c#L1057 OBJ_INFECT(obj1, obj2); } -static st_table *immediate_frozen_tbl = 0; - /* * call-seq: * obj.freeze -> obj @@ -1089,10 +1087,7 @@ rb_obj_freeze(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1087 if (!OBJ_FROZEN(obj)) { OBJ_FREEZE(obj); if (SPECIAL_CONST_P(obj)) { - if (!immediate_frozen_tbl) { - immediate_frozen_tbl = st_init_numtable(); - } - st_insert(immediate_frozen_tbl, obj, (st_data_t)Qtrue); + rb_bug("special consts should be frozen."); } } return obj; @@ -1112,12 +1107,7 @@ rb_obj_freeze(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1107 VALUE rb_obj_frozen_p(VALUE obj) { - if (OBJ_FROZEN(obj)) return Qtrue; - if (SPECIAL_CONST_P(obj)) { - if (!immediate_frozen_tbl) return Qfalse; - if (st_lookup(immediate_frozen_tbl, obj, 0)) return Qtrue; - } - return Qfalse; + return OBJ_FROZEN(obj) ? Qtrue : Qfalse; } Index: gc.c =================================================================== --- gc.c (revision 47522) +++ gc.c (revision 47523) @@ -2286,11 +2286,11 @@ should_be_callable(VALUE block) https://github.com/ruby/ruby/blob/trunk/gc.c#L2286 static void should_be_finalizable(VALUE obj) { - rb_check_frozen(obj); if (!FL_ABLE(obj)) { rb_raise(rb_eArgError, "cannot define finalizer for %s", rb_obj_classname(obj)); } + rb_check_frozen(obj); } /* Index: test/ruby/test_weakmap.rb =================================================================== --- test/ruby/test_weakmap.rb (revision 47522) +++ test/ruby/test_weakmap.rb (revision 47523) @@ -19,13 +19,13 @@ class TestWeakMap < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_weakmap.rb#L19 assert_raise(ArgumentError) {@wm[true] = x} assert_raise(ArgumentError) {@wm[false] = x} assert_raise(ArgumentError) {@wm[nil] = x} - assert_raise(RuntimeError) {@wm[42] = x} - assert_raise(RuntimeError) {@wm[:foo] = x} + assert_raise(ArgumentError) {@wm[42] = x} + assert_raise(ArgumentError) {@wm[:foo] = x} assert_raise(ArgumentError) {@wm[x] = true} assert_raise(ArgumentError) {@wm[x] = false} assert_raise(ArgumentError) {@wm[x] = nil} - assert_raise(RuntimeError) {@wm[x] = 42} - assert_raise(RuntimeError) {@wm[x] = :foo} + assert_raise(ArgumentError) {@wm[x] = 42} + assert_raise(ArgumentError) {@wm[x] = :foo} end def test_include? Index: test/ruby/test_eval.rb =================================================================== --- test/ruby/test_eval.rb (revision 47522) +++ test/ruby/test_eval.rb (revision 47523) @@ -130,7 +130,7 @@ class TestEval < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_eval.rb#L130 def forall_TYPE objects = [Object.new, [], nil, true, false] # TODO: check objects.each do |obj| - obj.instance_variable_set :@ivar, 12 + obj.instance_variable_set :@ivar, 12 unless obj.frozen? yield obj end end @@ -145,7 +145,7 @@ class TestEval < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_eval.rb#L145 assert_equal :sym, o.instance_eval(":sym") assert_equal 11, o.instance_eval("11") - assert_equal 12, o.instance_eval("@ivar") + assert_equal 12, o.instance_eval("@ivar") unless o.frozen? assert_equal 13, o.instance_eval("@@cvar") assert_equal 14, o.instance_eval("$gvar__eval") assert_equal 15, o.instance_eval("Const") @@ -155,7 +155,7 @@ class TestEval < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_eval.rb#L155 assert_equal "19", o.instance_eval(%q("1#{9}")) 1.times { - assert_equal 12, o.instance_eval("@ivar") + assert_equal 12, o.instance_eval("@ivar") unless o.frozen? assert_equal 13, o.instance_eval("@@cvar") assert_equal 14, o.instance_eval("$gvar__eval") assert_equal 15, o.instance_eval("Const") @@ -173,7 +173,7 @@ class TestEval < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_eval.rb#L173 assert_equal :sym, o.instance_eval { :sym } assert_equal 11, o.instance_eval { 11 } - assert_equal 12, o.instance_eval { @ivar } + assert_equal 12, o.instance_eval { @ivar } unless o.frozen? assert_equal 13, o.instance_eval { @@cvar } assert_equal 14, o.instance_eval { $gvar__eval } assert_equal 15, o.instance_eval { Const } @@ -183,7 +183,7 @@ class TestEval < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_eval.rb#L183 assert_equal "19", o.instance_eval { "1#{9}" } 1.times { - assert_equal 12, o.instance_eval { @ivar } + assert_equal 12, o.instance_eval { @ivar } unless o.frozen? assert_equal 13, o.instance_eval { @@cvar } assert_equal 14, o.instance_eval { $gvar__eval } assert_equal 15, o.instance_eval { Const } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/