зеркало из https://github.com/github/ruby.git
* gc.c (internal_object_p): should not expose singleton classes
without a metaclass. [Bug #11740] * class.c (rb_singleton_class_has_metaclass_p): added. * test/ruby/test_class.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
a7f6b862f0
Коммит
1bcee938d5
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Mon Dec 21 18:33:00 2015 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* gc.c (internal_object_p): should not expose singleton classes
|
||||
without a metaclass.
|
||||
[Bug #11740]
|
||||
|
||||
* class.c (rb_singleton_class_has_metaclass_p): added.
|
||||
|
||||
* test/ruby/test_class.rb: add a test.
|
||||
|
||||
Mon Dec 21 12:15:32 2015 Kimura Wataru <kimuraw@i.nifty.jp>
|
||||
|
||||
* test/ruby/test_io.rb: handled rlimit value same as r52277
|
||||
|
|
14
class.c
14
class.c
|
@ -442,6 +442,12 @@ rb_singleton_class_attached(VALUE klass, VALUE obj)
|
|||
*/
|
||||
#define META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k))
|
||||
|
||||
int
|
||||
rb_singleton_class_has_metaclass_p(VALUE sklass)
|
||||
{
|
||||
return rb_attr_get(METACLASS_OF(sklass), id_attached) == sklass;
|
||||
}
|
||||
|
||||
/*!
|
||||
* whether k has a metaclass
|
||||
* @retval 1 if \a k has a metaclass
|
||||
|
@ -449,7 +455,13 @@ rb_singleton_class_attached(VALUE klass, VALUE obj)
|
|||
*/
|
||||
#define HAVE_METACLASS_P(k) \
|
||||
(FL_TEST(METACLASS_OF(k), FL_SINGLETON) && \
|
||||
rb_ivar_get(METACLASS_OF(k), id_attached) == (k))
|
||||
rb_singleton_class_has_metaclass_p(k))
|
||||
|
||||
int
|
||||
rb_class_has_metaclass_p(VALUE klass)
|
||||
{
|
||||
return HAVE_METACLASS_P(klass);
|
||||
}
|
||||
|
||||
/*!
|
||||
* ensures \a klass belongs to its own eigenclass.
|
||||
|
|
7
gc.c
7
gc.c
|
@ -2400,6 +2400,13 @@ internal_object_p(VALUE obj)
|
|||
case T_NODE:
|
||||
case T_ZOMBIE:
|
||||
break;
|
||||
case T_CLASS:
|
||||
{
|
||||
if (FL_TEST(obj, FL_SINGLETON)) {
|
||||
int rb_singleton_class_has_metaclass_p(VALUE sklass);
|
||||
return rb_singleton_class_has_metaclass_p(obj) == 0;
|
||||
}
|
||||
}
|
||||
default:
|
||||
if (!p->as.basic.klass) break;
|
||||
return 0;
|
||||
|
|
|
@ -556,4 +556,24 @@ class TestClass < Test::Unit::TestCase
|
|||
}
|
||||
end;
|
||||
end
|
||||
|
||||
def test_should_not_expose_singleton_class_without_metaclass
|
||||
assert_normal_exit %q{
|
||||
klass = Class.new(Array)
|
||||
# The metaclass of +klass+ should handle #bla since it should inherit methods from meta:meta:Array
|
||||
def (Array.singleton_class).bla; :bla; end
|
||||
hidden = ObjectSpace.each_object(Class).find { |c| klass.is_a? c and c.inspect.include? klass.inspect }
|
||||
raise unless hidden.nil?
|
||||
}, '[Bug #11740]'
|
||||
|
||||
assert_normal_exit %q{
|
||||
klass = Class.new(Array)
|
||||
klass.singleton_class
|
||||
# The metaclass of +klass+ should handle #bla since it should inherit methods from meta:meta:Array
|
||||
def (Array.singleton_class).bla; :bla; end
|
||||
hidden = ObjectSpace.each_object(Class).find { |c| klass.is_a? c and c.inspect.include? klass.inspect }
|
||||
raise if hidden.nil?
|
||||
}, '[Bug #11740]'
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче