зеркало из https://github.com/github/ruby.git
vm_method.c: should not modify frozen objects
* vm_method.c (rb_method_entry_make, remove_method): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
94ee7c47cd
Коммит
b41909f603
|
@ -1,3 +1,7 @@
|
|||
Fri Sep 12 17:13:29 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* vm_method.c (rb_method_entry_make, remove_method): ditto.
|
||||
|
||||
Fri Sep 12 14:39:55 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
||||
|
||||
* gems/bundled_gems: Upgraded to test-unit-3.0.1 and minitest-5.4.1
|
||||
|
|
4
eval.c
4
eval.c
|
@ -409,6 +409,10 @@ rb_frozen_class_p(VALUE klass)
|
|||
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;
|
||||
|
||||
|
|
|
@ -384,4 +384,13 @@ class TestClass < Test::Unit::TestCase
|
|||
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
|
||||
|
|
|
@ -271,7 +271,7 @@ rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
|||
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));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче