Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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]) {
Expand Down
11 changes: 2 additions & 9 deletions test/ruby/test_allocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down