From e31750a6690238381c4a5bf97952d57275918098 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 25 Aug 2025 22:04:41 +0200 Subject: [PATCH 1/3] Revert "Omit extra allocation of Array object in Windows platform temporary" This reverts commit 6ab2cd0f69ff1591db3a0011b73d3b26a9a69412. --- test/ruby/test_allocation.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/ruby/test_allocation.rb b/test/ruby/test_allocation.rb index a3358ecff81697..a2ccd7bd659d0e 100644 --- a/test/ruby/test_allocation.rb +++ b/test/ruby/test_allocation.rb @@ -54,12 +54,7 @@ def self.num_allocations RB if num_arrays != $allocations[0] - if $allocations[0] - num_arrays == 1 && RUBY_PLATFORM =~ /mswin|mingw/ - # TODO: Must fix this condition - # Windows platforms may allocate an extra array after https://github.com/ruby/ruby/pull/14303 - else - failures << "Expected \#{num_arrays} array allocations for \#{check_code.inspect}, but \#{$allocations[0]} arrays allocated" - end + failures << "Expected \#{num_arrays} array allocations for \#{check_code.inspect}, but \#{$allocations[0]} arrays allocated" end if num_hashes != $allocations[1] failures << "Expected \#{num_hashes} hash allocations for \#{check_code.inspect}, but \#{$allocations[1]} hashes allocated" From cc3f14951f1a06fa746e8a574b9f9975b118df47 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 25 Aug 2025 22:06:58 +0200 Subject: [PATCH 2/3] Fix ObjectSpace.count_objects to allocate all symbols it uses eagerly * To not count them as program allocations. * Similar to https://github.com/ruby/ruby/pull/13906 --- gc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gc.c b/gc.c index 97367039af7949..d9efe43de54ff9 100644 --- a/gc.c +++ b/gc.c @@ -2490,6 +2490,10 @@ count_objects(int argc, VALUE *argv, VALUE os) types[i] = type_sym(i); } + // Same as type_sym, we need to create all key symbols in advance + VALUE total = ID2SYM(rb_intern("TOTAL")); + VALUE free = ID2SYM(rb_intern("FREE")); + rb_gc_impl_each_object(rb_gc_get_objspace(), count_objects_i, &data); if (NIL_P(hash)) { @@ -2498,8 +2502,8 @@ count_objects(int argc, VALUE *argv, VALUE os) else if (!RHASH_EMPTY_P(hash)) { rb_hash_stlike_foreach(hash, set_zero, hash); } - rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), SIZET2NUM(data.total)); - rb_hash_aset(hash, ID2SYM(rb_intern("FREE")), SIZET2NUM(data.freed)); + rb_hash_aset(hash, total, SIZET2NUM(data.total)); + rb_hash_aset(hash, free, SIZET2NUM(data.freed)); for (size_t i = 0; i <= T_MASK; i++) { if (data.counts[i]) { From b2e940a3740a558d6b5f8f7fbc5677ffa190c610 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 26 Aug 2025 11:16:04 +0900 Subject: [PATCH 3/3] Simplified assertion --- test/ruby/test_allocation.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/ruby/test_allocation.rb b/test/ruby/test_allocation.rb index a2ccd7bd659d0e..6ade391c951848 100644 --- a/test/ruby/test_allocation.rb +++ b/test/ruby/test_allocation.rb @@ -66,9 +66,7 @@ def self.num_allocations #{checks} - unless failures.empty? - assert_equal(true, false, failures.join("\n")) - end + assert_empty(failures) RUBY end