Skip to content

Commit 6ea893f

Browse files
committed
Add assertion for RCLASS_SET_PRIME_CLASSEXT_WRITABLE
When classes are booted, they should all be writeable unless namespaces are enabled. This commit adds an assertion to ensure that classes are writable.
1 parent 511b6bc commit 6ea893f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

class.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ class_alloc(VALUE flags, VALUE klass)
702702
RCLASS_PRIME_NS((VALUE)obj) = ns;
703703
// Classes/Modules defined in user namespaces are
704704
// writable directly because it exists only in a namespace.
705-
RCLASS_SET_PRIME_CLASSEXT_WRITABLE((VALUE)obj, NAMESPACE_USER_P(ns) ? true : false);
705+
RCLASS_SET_PRIME_CLASSEXT_WRITABLE((VALUE)obj, (NAMESPACE_USER_P(ns) || !rb_namespace_available()) ? true : false);
706706

707707
RCLASS_SET_ORIGIN((VALUE)obj, (VALUE)obj);
708708
RCLASS_SET_REFINED_CLASS((VALUE)obj, Qnil);
@@ -858,6 +858,8 @@ rb_class_new(VALUE super)
858858
RCLASS_SET_MAX_IV_COUNT(klass, RCLASS_MAX_IV_COUNT(super));
859859
}
860860

861+
RUBY_ASSERT(getenv("RUBY_NAMESPACE") || RCLASS_PRIME_CLASSEXT_WRITABLE_P(klass));
862+
861863
return klass;
862864
}
863865

gc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3279,12 +3279,14 @@ rb_gc_mark_children(void *objspace, VALUE obj)
32793279
// Skip updating max_iv_count if the prime classext is not writable
32803280
// because GC context doesn't provide information about namespaces.
32813281
if (RCLASS_PRIME_CLASSEXT_WRITABLE_P(klass)) {
3282-
VM_ASSERT(rb_shape_obj_too_complex_p(klass));
32833282
// Increment max_iv_count if applicable, used to determine size pool allocation
32843283
if (RCLASS_MAX_IV_COUNT(klass) < fields_count) {
32853284
RCLASS_SET_MAX_IV_COUNT(klass, fields_count);
32863285
}
32873286
}
3287+
else {
3288+
VM_ASSERT(rb_shape_obj_too_complex_p(klass));
3289+
}
32883290
}
32893291

32903292
break;

0 commit comments

Comments
 (0)