4444 * If unset, the prime classext is writable only from the root namespace.
4545 * 3: RCLASS_IS_INITIALIZED
4646 * Class has been initialized.
47+ * 4: RCLASS_NAMESPACEABLE
48+ * Is a builtin class that may be namespaced. It larger than a normal class.
4749 */
4850
4951/* Flags of T_ICLASS
5052 *
5153 * 2: RCLASS_PRIME_CLASSEXT_PRIME_WRITABLE
5254 * This module's prime classext is the only classext and writable from any namespaces.
5355 * If unset, the prime classext is writable only from the root namespace.
56+ * 4: RCLASS_NAMESPACEABLE
57+ * Is a builtin class that may be namespaced. It larger than a normal class.
5458 */
5559
5660/* Flags of T_MODULE
6569 * If unset, the prime classext is writable only from the root namespace.
6670 * 3: RCLASS_IS_INITIALIZED
6771 * Module has been initialized.
72+ * 4: RCLASS_NAMESPACEABLE
73+ * Is a builtin class that may be namespaced. It larger than a normal class.
6874 */
6975
7076#define METACLASS_OF (k ) RBASIC(k)->klass
@@ -662,6 +668,8 @@ class_alloc(enum ruby_value_type type, VALUE klass)
662668
663669 VALUE flags = type ;
664670 if (RGENGC_WB_PROTECTED_CLASS ) flags |= FL_WB_PROTECTED ;
671+ if (!ruby_namespace_init_done ) flags |= RCLASS_NAMESPACEABLE ;
672+
665673 NEWOBJ_OF (obj , struct RClass , klass , flags , alloc_size , 0 );
666674
667675 memset (RCLASS_EXT_PRIME (obj ), 0 , sizeof (rb_classext_t ));
@@ -676,7 +684,7 @@ class_alloc(enum ruby_value_type type, VALUE klass)
676684 RCLASS_PRIME_NS ((VALUE )obj ) = ns ;
677685 // Classes/Modules defined in user namespaces are
678686 // writable directly because it exists only in a namespace.
679- RCLASS_SET_PRIME_CLASSEXT_WRITABLE ((VALUE )obj , ! rb_namespace_available () || NAMESPACE_USER_P (ns ) ? true : false );
687+ RCLASS_SET_PRIME_CLASSEXT_WRITABLE ((VALUE )obj , ruby_namespace_init_done || NAMESPACE_USER_P (ns ));
680688
681689 RCLASS_SET_ORIGIN ((VALUE )obj , (VALUE )obj );
682690 RCLASS_SET_REFINED_CLASS ((VALUE )obj , Qnil );
0 commit comments