Commit 279fce05 authored by Ryan Scott's avatar Ryan Scott

ObjectSpace.count_objects was incorrectly checking if an object was already...

ObjectSpace.count_objects was incorrectly checking if an object was already freed. Amended the count_objects test to ensure the correct distinction
parent c2d1105a
......@@ -1168,6 +1168,7 @@ mrb_value os_count_objects(mrb_state *mrb, mrb_value self)
size_t total = 0;
size_t i;
mrb_value hash;
RVALUE *free;
struct heap_page* page = mrb->heaps;
if (mrb_get_args(mrb, "|H", &hash) == 0) {
......@@ -1188,13 +1189,15 @@ mrb_value os_count_objects(mrb_state *mrb, mrb_value self)
p = page->objects;
pend = p + MRB_HEAP_PAGE_SIZE;
for (;p < pend; p++) {
if (p->as.basic.flags) {
counts[mrb_type(p->as.basic)]++;
}
else {
freed++;
}
counts[mrb_type(p->as.basic)]++;
}
free = (RVALUE*)page->freelist;
while (free) {
freed++;
free = (RVALUE*)free->as.free.next;
}
total += MRB_HEAP_PAGE_SIZE;
page = page->next;
}
......
......@@ -16,4 +16,20 @@ assert('ObjectSpace.count_objects') do
h0 = {:MRB_TT_FOO=>1000}
h = ObjectSpace.count_objects(h0)
assert_false(h0.has_key?(:MRB_TT_FOO))
GC.start
h_after = {}
h_before = ObjectSpace.count_objects
objs = []
1000.times do
objs << {}
end
objs = nil
ObjectSpace.count_objects(h)
GC.start
ObjectSpace.count_objects(h_after)
assert_equal(h_before[:MRB_TT_HASH] + 1000, h[:MRB_TT_HASH])
assert_equal(h_before[:MRB_TT_HASH], h_after[:MRB_TT_HASH])
end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment