diff options
author | Jeremy Evans <code@jeremyevans.net> | 2025-08-31 03:24:25 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-30 11:24:25 -0700 |
commit | 5c7dfe85a1dc49334e2828791f0ade42eee662db (patch) | |
tree | 6df4cea1d0df4a839f893e2620c37c42c770ad9c /object.c | |
parent | dd4e7801f3f2b7e258016b8e22c6d8870516166b (diff) |
Initialize class dup/clone before calling initialize_dup/initialize_clone
Previously, you could override the class initialize_dup/initialize_clone
method and the class hierarchy would not be set correctly inside the
method before calling super.
This removes Module#initialize_copy, and instead makes Object#dup/clone
call the underlying C function (rb_mod_init_copy) before calling the
appropriate initialize_dup/initialize_clone method.
This results in the following fixes:
* The appropriate initialize_dup method is called (dup on a class
will respect superclass initialize_dup).
* Inside class initialize_dup/initialize_clone/initialize_copy,
class ancestor hierarchy is correct.
* Calling singleton_class inside initialize_dup no longer raises
a TypeError later in dup.
* Calling singleton_class.ancestors inside initialize_dup no
longer results in missing ancestors.
Fixes [Bug #21538]
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 3 |
1 files changed, 1 insertions, 2 deletions
@@ -409,7 +409,7 @@ init_copy(VALUE dest, VALUE obj) break; case T_CLASS: case T_MODULE: - // noop: handled in class.c: rb_mod_init_copy + rb_mod_init_copy(dest, obj); break; case T_OBJECT: rb_obj_copy_ivar(dest, obj); @@ -4571,7 +4571,6 @@ InitVM_Object(void) rb_define_method(rb_cModule, "<=", rb_class_inherited_p, 1); rb_define_method(rb_cModule, ">", rb_mod_gt, 1); rb_define_method(rb_cModule, ">=", rb_mod_ge, 1); - rb_define_method(rb_cModule, "initialize_copy", rb_mod_init_copy, 1); /* in class.c */ rb_define_method(rb_cModule, "to_s", rb_mod_to_s, 0); rb_define_alias(rb_cModule, "inspect", "to_s"); rb_define_method(rb_cModule, "included_modules", rb_mod_included_modules, 0); /* in class.c */ |