summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-22 13:15:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-22 13:15:58 +0000
commit96ac47c25109abfd846eb45ae6cb6b56c8b178e3 (patch)
tree23a6763c57b782d374aa8a02deba2a4a7aabd7f6 /class.c
parent3f90a4ae1e5a6c3dcf83ece419019a1797caed04 (diff)
gc.c: do not expose internal singleton class
* gc.c (internal_object_p): should not expose singleton classes without a metaclass. based on patches by ko1 and shugo. [Bug #11740] * class.c (rb_singleton_class_object_p): added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/class.c b/class.c
index f95890b..a72f4dc 100644
--- a/class.c
+++ b/class.c
@@ -442,6 +442,19 @@ rb_singleton_class_attached(VALUE klass, VALUE obj)
*/
#define META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k))
+static int
+rb_singleton_class_has_metaclass_p(VALUE sklass)
+{
+ return rb_attr_get(METACLASS_OF(sklass), id_attached) == sklass;
+}
+
+int
+rb_singleton_class_internal_p(VALUE sklass)
+{
+ return (RB_TYPE_P(rb_attr_get(sklass, id_attached), T_CLASS) &&
+ !rb_singleton_class_has_metaclass_p(sklass));
+}
+
/*!
* whether k has a metaclass
* @retval 1 if \a k has a metaclass
@@ -449,7 +462,7 @@ 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))
/*!
* ensures \a klass belongs to its own eigenclass.