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]) { diff --git a/test/ruby/test_allocation.rb b/test/ruby/test_allocation.rb index a3358ecff81697..6ade391c951848 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" @@ -71,9 +66,7 @@ def self.num_allocations #{checks} - unless failures.empty? - assert_equal(true, false, failures.join("\n")) - end + assert_empty(failures) RUBY end