ruby-changes:35469
From: nobu <ko1@a...>
Date: Fri, 12 Sep 2014 17:13:47 +0900 (JST)
Subject: [ruby-changes:35469] nobu:r47551 (trunk): vm_method.c: should not modify frozen objects
nobu 2014-09-12 17:13:28 +0900 (Fri, 12 Sep 2014) New Revision: 47551 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47551 Log: vm_method.c: should not modify frozen objects * vm_method.c (rb_method_entry_make, remove_method): ditto. Modified files: trunk/ChangeLog trunk/eval.c trunk/test/ruby/test_class.rb trunk/vm_method.c Index: ChangeLog =================================================================== --- ChangeLog (revision 47550) +++ ChangeLog (revision 47551) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Sep 12 17:13:29 2014 Nobuyoshi Nakada <nobu@r...> + + * vm_method.c (rb_method_entry_make, remove_method): ditto. + Fri Sep 12 14:39:55 2014 SHIBATA Hiroshi <shibata.hiroshi@g...> * gems/bundled_gems: Upgraded to test-unit-3.0.1 and minitest-5.4.1 Index: vm_method.c =================================================================== --- vm_method.c (revision 47550) +++ vm_method.c (revision 47551) @@ -271,7 +271,7 @@ rb_method_entry_make(VALUE klass, ID mid https://github.com/ruby/ruby/blob/trunk/vm_method.c#L271 } } - rb_check_frozen(klass); + rb_frozen_class_p(klass); #if NOEX_NOREDEF rklass = klass; #endif @@ -746,7 +746,7 @@ remove_method(VALUE klass, ID mid) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L746 VALUE self = klass; klass = RCLASS_ORIGIN(klass); - rb_check_frozen(klass); + rb_frozen_class_p(klass); if (mid == object_id || mid == id__send__ || mid == idInitialize) { rb_warn("removing `%s' may cause serious problems", rb_id2name(mid)); } Index: eval.c =================================================================== --- eval.c (revision 47550) +++ eval.c (revision 47551) @@ -409,6 +409,10 @@ rb_frozen_class_p(VALUE klass) https://github.com/ruby/ruby/blob/trunk/eval.c#L409 noclass: Check_Type(klass, T_CLASS); } + if (FL_TEST(klass, FL_SINGLETON)) { + VALUE obj = rb_ivar_get(klass, id__attached__); + if (OBJ_FROZEN(obj)) OBJ_FREEZE(klass); + } if (OBJ_FROZEN(klass)) { const char *desc; Index: test/ruby/test_class.rb =================================================================== --- test/ruby/test_class.rb (revision 47550) +++ test/ruby/test_class.rb (revision 47551) @@ -384,4 +384,13 @@ class TestClass < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_class.rb#L384 Class.new.freeze.clone.to_s } end + + def test_singleton_class_of_frozen_object + obj = Object.new + c = obj.singleton_class + obj.freeze + assert_raise(RuntimeError, /frozen object/) { + c.class_eval {def f; end} + } + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/