Only call RCLASS_SET_ALLOCATOR on T_CLASS objects
It's invalid to set an allocator on a T_ICLASS or T_MODULE, as those use the other fields from the union.
This commit is contained in:
parent
e01e89f55c
commit
05cdcfcefd
Notes:
git
2025-05-23 17:34:01 +00:00
6
class.c
6
class.c
@ -700,7 +700,6 @@ class_alloc(VALUE flags, VALUE klass)
|
||||
|
||||
RCLASS_SET_ORIGIN((VALUE)obj, (VALUE)obj);
|
||||
RCLASS_SET_REFINED_CLASS((VALUE)obj, Qnil);
|
||||
RCLASS_SET_ALLOCATOR((VALUE)obj, 0);
|
||||
|
||||
RCLASS_SET_SUBCLASSES((VALUE)obj, anchor);
|
||||
|
||||
@ -1044,7 +1043,9 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
|
||||
RBASIC_SET_CLASS(clone, rb_singleton_class_clone(orig));
|
||||
rb_singleton_class_attached(METACLASS_OF(clone), (VALUE)clone);
|
||||
}
|
||||
RCLASS_SET_ALLOCATOR(clone, RCLASS_ALLOCATOR(orig));
|
||||
if (BUILTIN_TYPE(clone) == T_CLASS) {
|
||||
RCLASS_SET_ALLOCATOR(clone, RCLASS_ALLOCATOR(orig));
|
||||
}
|
||||
copy_tables(clone, orig);
|
||||
if (RCLASS_M_TBL(orig)) {
|
||||
struct clone_method_arg arg;
|
||||
@ -1085,7 +1086,6 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
|
||||
rb_class_set_super(prev_clone_p, clone_p);
|
||||
prev_clone_p = clone_p;
|
||||
RCLASS_SET_CONST_TBL(clone_p, RCLASS_CONST_TBL(p), false);
|
||||
RCLASS_SET_ALLOCATOR(clone_p, RCLASS_ALLOCATOR(p));
|
||||
if (RB_TYPE_P(clone, T_CLASS)) {
|
||||
RCLASS_SET_INCLUDER(clone_p, clone);
|
||||
}
|
||||
|
@ -667,7 +667,8 @@ RCLASS_ALLOCATOR(VALUE klass)
|
||||
static inline void
|
||||
RCLASS_SET_ALLOCATOR(VALUE klass, rb_alloc_func_t allocator)
|
||||
{
|
||||
assert(!RCLASS_SINGLETON_P(klass));
|
||||
RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS));
|
||||
RUBY_ASSERT(!RCLASS_SINGLETON_P(klass));
|
||||
RCLASS_EXT_PRIME(klass)->as.class.allocator = allocator; // Allocator is set only on the initial definition
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user