diff options
| author | John Hawthorn <john@hawthorn.email> | 2026-03-21 09:09:57 -0700 |
|---|---|---|
| committer | John Hawthorn <john@hawthorn.email> | 2026-03-25 12:51:46 -0700 |
| commit | 111215de2758666894ba0a2095d86b731ffd5af3 (patch) | |
| tree | 690eafd3fed50296302ffc740d849fe39f8ae7fd /object.c | |
| parent | a0583318d3ab3495c5f1e7c03d65e24b9ddc60e3 (diff) | |
Copy allocator to subclasses at boot and on change
Copy the allocator from superclass to subclass at class creation time,
so rb_get_alloc_func no longer needs to walk the ancestor chain.
This expands on 68ffc8db088a7b29613a3746be5cc996be9f66fe, which did this
copy, but only for classes defined in Ruby (ex. `class Foo`). And allows
us to simple read the allocator field for any class to get the correct
value.
To keep this correct when rb_define_alloc_func is called after
subclasses already exist, propagate the new allocator down to all
subclasses. An RCLASS_ALLOCATOR_DEFINED flag distinguishes classes with
an explicitly set allocator from those that inherited one, so
propagation stops at subclasses that define their own.
Diffstat (limited to 'object.c')
| -rw-r--r-- | object.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -2253,6 +2253,7 @@ rb_class_initialize(int argc, VALUE *argv, VALUE klass) } } rb_class_set_super(klass, super); + RCLASS_SET_ALLOCATOR(klass, RCLASS_ALLOCATOR(super)); rb_make_metaclass(klass, RBASIC(super)->klass); rb_class_inherited(super, klass); rb_mod_initialize_exec(klass); @@ -4448,7 +4449,6 @@ InitVM_Object(void) #endif rb_define_private_method(rb_cBasicObject, "initialize", rb_obj_initialize, 0); - rb_define_alloc_func(rb_cBasicObject, rb_class_allocate_instance); rb_define_method(rb_cBasicObject, "==", rb_obj_equal, 1); rb_define_method(rb_cBasicObject, "equal?", rb_obj_equal, 1); rb_define_method(rb_cBasicObject, "!", rb_obj_not, 0); |
