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.
This commit is contained in:
parent
511b6bcb53
commit
6ea893f376
Notes:
git
2025-05-21 16:51:46 +00:00
4
class.c
4
class.c
@ -702,7 +702,7 @@ class_alloc(VALUE flags, VALUE klass)
|
||||
RCLASS_PRIME_NS((VALUE)obj) = ns;
|
||||
// Classes/Modules defined in user namespaces are
|
||||
// writable directly because it exists only in a namespace.
|
||||
RCLASS_SET_PRIME_CLASSEXT_WRITABLE((VALUE)obj, NAMESPACE_USER_P(ns) ? true : false);
|
||||
RCLASS_SET_PRIME_CLASSEXT_WRITABLE((VALUE)obj, (NAMESPACE_USER_P(ns) || !rb_namespace_available()) ? true : false);
|
||||
|
||||
RCLASS_SET_ORIGIN((VALUE)obj, (VALUE)obj);
|
||||
RCLASS_SET_REFINED_CLASS((VALUE)obj, Qnil);
|
||||
@ -858,6 +858,8 @@ rb_class_new(VALUE super)
|
||||
RCLASS_SET_MAX_IV_COUNT(klass, RCLASS_MAX_IV_COUNT(super));
|
||||
}
|
||||
|
||||
RUBY_ASSERT(getenv("RUBY_NAMESPACE") || RCLASS_PRIME_CLASSEXT_WRITABLE_P(klass));
|
||||
|
||||
return klass;
|
||||
}
|
||||
|
||||
|
4
gc.c
4
gc.c
@ -3279,12 +3279,14 @@ rb_gc_mark_children(void *objspace, VALUE obj)
|
||||
// Skip updating max_iv_count if the prime classext is not writable
|
||||
// because GC context doesn't provide information about namespaces.
|
||||
if (RCLASS_PRIME_CLASSEXT_WRITABLE_P(klass)) {
|
||||
VM_ASSERT(rb_shape_obj_too_complex_p(klass));
|
||||
// Increment max_iv_count if applicable, used to determine size pool allocation
|
||||
if (RCLASS_MAX_IV_COUNT(klass) < fields_count) {
|
||||
RCLASS_SET_MAX_IV_COUNT(klass, fields_count);
|
||||
}
|
||||
}
|
||||
else {
|
||||
VM_ASSERT(rb_shape_obj_too_complex_p(klass));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user