@@ -336,26 +336,31 @@ RCLASS_SET_NAMESPACE_CLASSEXT(VALUE obj, const rb_namespace_t *ns, rb_classext_t
336336 return first_set ;
337337}
338338
339+ #define VM_ASSERT_NAMESPACEABLE_TYPE (klass ) \
340+ VM_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_MODULE) || RB_TYPE_P(klass, T_ICLASS), "%s is not namespaceable type", rb_type_str(BUILTIN_TYPE(klass)))
341+
339342static inline bool
340343RCLASS_PRIME_CLASSEXT_READABLE_P (VALUE klass )
341344{
342- VM_ASSERT (RB_TYPE_P (klass , T_CLASS ) || RB_TYPE_P (klass , T_MODULE ) || RB_TYPE_P (klass , T_ICLASS ));
345+ VM_ASSERT (klass != 0 , "klass should be a valid object" );
346+ VM_ASSERT_NAMESPACEABLE_TYPE (klass );
343347 // if the lookup table exists, then it means the prime classext is NOT directly readable.
344348 return !FL_TEST_RAW (klass , RCLASS_NAMESPACEABLE ) || RCLASS_CLASSEXT_TBL (klass ) == NULL ;
345349}
346350
347351static inline bool
348352RCLASS_PRIME_CLASSEXT_WRITABLE_P (VALUE klass )
349353{
350- VM_ASSERT (RB_TYPE_P (klass , T_CLASS ) || RB_TYPE_P (klass , T_MODULE ) || RB_TYPE_P (klass , T_ICLASS ));
354+ VM_ASSERT (klass != 0 , "klass should be a valid object" );
355+ VM_ASSERT_NAMESPACEABLE_TYPE (klass );
351356 return FL_TEST (klass , RCLASS_PRIME_CLASSEXT_WRITABLE );
352357}
353358
354359static inline void
355360RCLASS_SET_PRIME_CLASSEXT_WRITABLE (VALUE klass , bool writable )
356361{
357- VM_ASSERT (RB_TYPE_P ( klass , T_CLASS ) || RB_TYPE_P ( klass , T_MODULE ) || RB_TYPE_P ( klass , T_ICLASS ) );
358-
362+ VM_ASSERT (klass != 0 , " klass should be a valid object" );
363+ VM_ASSERT_NAMESPACEABLE_TYPE ( klass );
359364 if (writable ) {
360365 FL_SET (klass , RCLASS_PRIME_CLASSEXT_WRITABLE );
361366 }
@@ -429,6 +434,7 @@ RCLASS_EXT_WRITABLE_LOOKUP(VALUE obj, const rb_namespace_t *ns)
429434 ext = rb_class_duplicate_classext (RCLASS_EXT_PRIME (obj ), obj , ns );
430435 first_set = RCLASS_SET_NAMESPACE_CLASSEXT (obj , ns , ext );
431436 if (first_set ) {
437+ // TODO: are there any case that a class/module become non-writable after its birthtime?
432438 RCLASS_SET_PRIME_CLASSEXT_WRITABLE (obj , false);
433439 }
434440 }
0 commit comments