object.c: improve fake_class_p to also handle T_MODULE

This requires ensuring T_MODULE never has FL_SINGLETON set,
so RMODULE_IS_REFINEMENT had to be moved.
This commit is contained in:
Jean Boussier committed 2025-08-30 12:21:10 +02:00
1 parent ac06d5ccf3
commit b67c16c477
2 files changed
+16 -14

No files matched your search

+4 -2
View File
@@ -62,8 +62,8 @@
* 0: RCLASS_IS_ROOT
* The class has been added to the VM roots. Will always be marked and pinned.
* This is done for classes defined from C to allow storing them in global variables.
* 1: RMODULE_IS_REFINEMENT
* Module is used for refinements.
* 1: <reserved>
* Ensures that RUBY_FL_SINGLETON is never set on a T_MODULE. See `rb_class_real`.
* 2: RCLASS_PRIME_CLASSEXT_PRIME_WRITABLE
* This module's prime classext is the only classext and writable from any namespaces.
* If unset, the prime classext is writable only from the root namespace.
@@ -71,6 +71,8 @@
* Module has been initialized.
* 4: RCLASS_NAMESPACEABLE
* Is a builtin class that may be namespaced. It larger than a normal class.
* 5: RMODULE_IS_REFINEMENT
* Module is used for refinements.
*/
#define METACLASS_OF(k) RBASIC(k)->klass
+12 -12
View File
@@ -278,25 +278,25 @@ rb_obj_not_equal(VALUE obj1, VALUE obj2)
return rb_obj_not(result);
}
VALUE
rb_class_real(VALUE cl)
{
while (cl &&
(RCLASS_SINGLETON_P(cl) || BUILTIN_TYPE(cl) == T_ICLASS)) {
cl = RCLASS_SUPER(cl);
}
return cl;
}
static inline VALUE
fake_class_p(VALUE klass)
{
RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_ICLASS));
STATIC_ASSERT(t_iclass_overlap, !(T_CLASS & T_ICLASS));
RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_MODULE) || RB_TYPE_P(klass, T_ICLASS));
STATIC_ASSERT(t_iclass_overlap_t_class, !(T_CLASS & T_ICLASS));
STATIC_ASSERT(t_iclass_overlap_t_module, !(T_MODULE & T_ICLASS));
return FL_TEST_RAW(klass, T_ICLASS | FL_SINGLETON);
}
VALUE
rb_class_real(VALUE cl)
{
while (RB_UNLIKELY(cl && fake_class_p(cl))) {
cl = RCLASS_SUPER(cl);
}
return cl;
}
VALUE
rb_obj_class(VALUE obj)
{