@@ -116,8 +116,10 @@ struct rb_classext_struct {
116116 struct {
117117 VALUE attached_object ;
118118 } singleton_class ;
119+ struct {
120+ const VALUE includer ;
121+ } iclass ;
119122 } as ;
120- const VALUE includer ;
121123 attr_index_t max_iv_count ;
122124 unsigned char variation_count ;
123125 bool permanent_classpath : 1 ;
@@ -184,7 +186,7 @@ static inline rb_classext_t * RCLASS_EXT_WRITABLE(VALUE obj);
184186#define RCLASSEXT_ORIGIN (ext ) (ext->origin_)
185187#define RCLASSEXT_REFINED_CLASS (ext ) (ext->refined_class)
186188// class.allocator/singleton_class.attached_object are not accessed directly via RCLASSEXT_*
187- #define RCLASSEXT_INCLUDER (ext ) (ext->includer)
189+ #define RCLASSEXT_INCLUDER (ext ) (ext->as.iclass. includer)
188190#define RCLASSEXT_MAX_IV_COUNT (ext ) (ext->max_iv_count)
189191#define RCLASSEXT_VARIATION_COUNT (ext ) (ext->variation_count)
190192#define RCLASSEXT_PERMANENT_CLASSPATH (ext ) (ext->permanent_classpath)
@@ -237,7 +239,7 @@ static inline void RCLASSEXT_SET_INCLUDER(rb_classext_t *ext, VALUE klass, VALUE
237239// namespaces don't make changes on these refined_class/attached_object/includer
238240#define RCLASS_REFINED_CLASS (c ) (RCLASS_EXT_PRIME(c)->refined_class)
239241#define RCLASS_ATTACHED_OBJECT (c ) (RCLASS_EXT_PRIME(c)->as.singleton_class.attached_object)
240- #define RCLASS_INCLUDER (c ) (RCLASS_EXT_PRIME(c)->includer)
242+ #define RCLASS_INCLUDER (c ) (RCLASS_EXT_PRIME(c)->as.iclass. includer)
241243
242244// Writable classext entries (instead of RCLASS_SET_*) because member data will be operated directly
243245#define RCLASS_WRITABLE_M_TBL (c ) (RCLASS_EXT_WRITABLE(c)->m_tbl)
@@ -459,6 +461,7 @@ RCLASSEXT_SET_ORIGIN(rb_classext_t *ext, VALUE klass, VALUE origin)
459461static inline void
460462RCLASSEXT_SET_INCLUDER (rb_classext_t * ext , VALUE klass , VALUE includer )
461463{
464+ RUBY_ASSERT (RB_TYPE_P (klass , T_ICLASS ));
462465 RB_OBJ_WRITE (klass , & (RCLASSEXT_INCLUDER (ext )), includer );
463466}
464467
@@ -651,7 +654,7 @@ RCLASS_SET_REFINED_CLASS(VALUE klass, VALUE refined)
651654static inline rb_alloc_func_t
652655RCLASS_ALLOCATOR (VALUE klass )
653656{
654- if (RCLASS_SINGLETON_P (klass )) {
657+ if (RCLASS_SINGLETON_P (klass ) || RB_TYPE_P ( klass , T_ICLASS ) ) {
655658 return 0 ;
656659 }
657660 return RCLASS_EXT_PRIME (klass )-> as .class .allocator ;
@@ -702,6 +705,7 @@ RICLASS_OWNS_M_TBL_P(VALUE iclass)
702705static inline void
703706RCLASS_SET_INCLUDER (VALUE iclass , VALUE klass )
704707{
708+ RUBY_ASSERT (RB_TYPE_P (iclass , T_ICLASS ));
705709 RB_OBJ_WRITE (iclass , & RCLASS_INCLUDER (iclass ), klass );
706710}
707711
0 commit comments