diff options
author | NARUSE, Yui <[email protected]> | 2024-03-21 14:31:36 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2024-03-21 05:31:36 +0000 |
commit | f79b1d1ef1f7aa64d20f0eadbb3b0f8f7084deb3 (patch) | |
tree | 9e7a3db4bad45e170e273e71de4766a696fca8c6 /class.c | |
parent | 57a0afe2090b8d05673d650b1e8bf9ae67449b1f (diff) |
merge revision(s) e626da82eae3d437b84d4f9ead0164d436b08e1a,f3af5ae7e6c1c096bbfe46d69de825a02b1696cf: [Backport #20311] (#10312)
Don't pin named structs defined in Ruby
[Bug #20311]
`rb_define_class_under` assumes it's called from C and that the
reference might be held in a C global variable, so it adds the
class to the VM root.
In the case of `Struct.new('Name')` it's wasteful and make
the struct immortal.
Make Struct memory leak test faster
[Bug #20311]
It times out on some platform, so we can reduce iterations.
On my machine it completes in 250ms and RSS grows 8X.
Diffstat (limited to 'class.c')
-rw-r--r-- | class.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -1007,7 +1007,7 @@ rb_define_class_under(VALUE outer, const char *name, VALUE super) } VALUE -rb_define_class_id_under(VALUE outer, ID id, VALUE super) +rb_define_class_id_under_no_pin(VALUE outer, ID id, VALUE super) { VALUE klass; @@ -1024,8 +1024,6 @@ rb_define_class_id_under(VALUE outer, ID id, VALUE super) " (%"PRIsVALUE" is given but was %"PRIsVALUE")", outer, rb_id2str(id), RCLASS_SUPER(klass), super); } - /* Class may have been defined in Ruby and not pin-rooted */ - rb_vm_add_root_module(klass); return klass; } @@ -1037,12 +1035,19 @@ rb_define_class_id_under(VALUE outer, ID id, VALUE super) rb_set_class_path_string(klass, outer, rb_id2str(id)); rb_const_set(outer, id, klass); rb_class_inherited(super, klass); - rb_vm_add_root_module(klass); return klass; } VALUE +rb_define_class_id_under(VALUE outer, ID id, VALUE super) +{ + VALUE klass = rb_define_class_id_under_no_pin(outer, id, super); + rb_vm_add_root_module(klass); + return klass; +} + +VALUE rb_module_s_alloc(VALUE klass) { VALUE mod = class_alloc(T_MODULE, klass); |