1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

class.c: freeze meta class only

* class.c (singleton_class_of): should not propagete freezing to
  meta meta class.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-09-13 13:03:46 +00:00
parent 05b374b824
commit 4df147d6e8
3 changed files with 7 additions and 3 deletions

View file

@ -1575,7 +1575,7 @@ singleton_class_of(VALUE obj)
else {
FL_UNSET(klass, FL_TAINT);
}
if (OBJ_FROZEN(obj)) OBJ_FREEZE(klass);
if (OBJ_FROZEN(obj)) OBJ_FREEZE_RAW(klass);
return klass;
}

View file

@ -1105,6 +1105,7 @@ struct RStruct {
RBASIC(x)->flags |= RBASIC(s)->flags & FL_TAINT : 0)
#define OBJ_FROZEN(x) (FL_ABLE(x) ? !!(RBASIC(x)->flags&FL_FREEZE) : 1)
#define OBJ_FREEZE_RAW(x) (RBASIC(x)->flags |= FL_FREEZE)
#define OBJ_FREEZE(x) rb_obj_freeze_inline((VALUE)x)
static inline void
@ -1112,9 +1113,9 @@ rb_obj_freeze_inline(VALUE x)
{
if (FL_ABLE(x)) {
VALUE klass = RBASIC_CLASS(x);
RBASIC(x)->flags |= FL_FREEZE;
OBJ_FREEZE_RAW(x);
if (FL_TEST(klass, (FL_SINGLETON|FL_FREEZE)) == FL_SINGLETON) {
RBASIC(klass)->flags |= FL_FREEZE;
OBJ_FREEZE_RAW(klass);
}
}
}

View file

@ -392,6 +392,9 @@ class TestClass < Test::Unit::TestCase
assert_raise_with_message(RuntimeError, /frozen object/) {
c.class_eval {def f; end}
}
end
def test_singleton_class_message
c = Class.new.freeze
assert_raise_with_message(RuntimeError, /frozen Class/) {
def c.f; end