class.c: do not freeze meta-meta-class
* class.c (rb_freeze_singleton_class): should not propagate to meta-meta-class, and so on, which is shared with the original class. fix occational exceptions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c7d0edb5b6
commit
d9a597408f
13
class.c
13
class.c
@ -1578,6 +1578,19 @@ singleton_class_of(VALUE obj)
|
|||||||
return klass;
|
return klass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rb_freeze_singleton_class(VALUE x)
|
||||||
|
{
|
||||||
|
/* should not propagate to meta-meta-class, and so on */
|
||||||
|
if (!(RBASIC(x)->flags & FL_SINGLETON)) {
|
||||||
|
VALUE klass = RBASIC_CLASS(x);
|
||||||
|
klass = RCLASS_ORIGIN(klass);
|
||||||
|
if (FL_TEST(klass, (FL_SINGLETON|FL_FREEZE)) == FL_SINGLETON) {
|
||||||
|
OBJ_FREEZE_RAW(klass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Returns the singleton class of \a obj, or nil if obj is not a
|
* Returns the singleton class of \a obj, or nil if obj is not a
|
||||||
* singleton object.
|
* singleton object.
|
||||||
|
@ -1108,14 +1108,15 @@ struct RStruct {
|
|||||||
#define OBJ_FREEZE_RAW(x) (RBASIC(x)->flags |= FL_FREEZE)
|
#define OBJ_FREEZE_RAW(x) (RBASIC(x)->flags |= FL_FREEZE)
|
||||||
#define OBJ_FREEZE(x) rb_obj_freeze_inline((VALUE)x)
|
#define OBJ_FREEZE(x) rb_obj_freeze_inline((VALUE)x)
|
||||||
|
|
||||||
|
void rb_freeze_singleton_class(VALUE klass);
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
rb_obj_freeze_inline(VALUE x)
|
rb_obj_freeze_inline(VALUE x)
|
||||||
{
|
{
|
||||||
if (FL_ABLE(x)) {
|
if (FL_ABLE(x)) {
|
||||||
VALUE klass = RBASIC_CLASS(x);
|
|
||||||
OBJ_FREEZE_RAW(x);
|
OBJ_FREEZE_RAW(x);
|
||||||
if (FL_TEST(klass, (FL_SINGLETON|FL_FREEZE)) == FL_SINGLETON) {
|
if (!(RBASIC(x)->flags & FL_SINGLETON)) {
|
||||||
OBJ_FREEZE_RAW(klass);
|
rb_freeze_singleton_class(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -914,25 +914,34 @@ class TestModule < Test::Unit::TestCase
|
|||||||
assert_include(c.constants(false), :Foo, bug9413)
|
assert_include(c.constants(false), :Foo, bug9413)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_frozen_class
|
def test_frozen_module
|
||||||
m = Module.new
|
m = Module.new
|
||||||
m.freeze
|
m.freeze
|
||||||
assert_raise(RuntimeError) do
|
assert_raise(RuntimeError) do
|
||||||
m.instance_eval { undef_method(:foo) }
|
m.instance_eval { undef_method(:foo) }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_frozen_class
|
||||||
c = Class.new
|
c = Class.new
|
||||||
c.freeze
|
c.freeze
|
||||||
assert_raise(RuntimeError) do
|
assert_raise(RuntimeError) do
|
||||||
c.instance_eval { undef_method(:foo) }
|
c.instance_eval { undef_method(:foo) }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
o = Object.new
|
def test_frozen_singleton_class
|
||||||
|
klass = Class.new
|
||||||
|
o = klass.new
|
||||||
c = class << o; self; end
|
c = class << o; self; end
|
||||||
c.freeze
|
c.freeze
|
||||||
assert_raise(RuntimeError) do
|
assert_raise_with_message(RuntimeError, /frozen/) do
|
||||||
c.instance_eval { undef_method(:foo) }
|
c.instance_eval { undef_method(:foo) }
|
||||||
end
|
end
|
||||||
|
klass.class_eval do
|
||||||
|
def self.foo
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_method_defined
|
def test_method_defined
|
||||||
|
Loading…
x
Reference in New Issue
Block a user