Commit c4f14755 authored by take_cheeze's avatar take_cheeze

Always increment `total` field of `os_count_struct` in callback.

Check sum of `ObjectSpace.count_objects` values is twice of total objects count.
(Which is CRuby's behavior.)
parent 63dc51c2
......@@ -15,12 +15,13 @@ os_count_object_type(mrb_state *mrb, struct RBasic *obj, void *data)
struct os_count_struct *obj_count;
obj_count = (struct os_count_struct*)data;
obj_count->total++;
if (is_dead(mrb, obj)) {
obj_count->freed++;
}
else {
obj_count->counts[obj->tt]++;
obj_count->total++;
}
}
......
......@@ -10,6 +10,8 @@ assert('ObjectSpace.count_objects') do
assert_true(h.has_key?(:FREE))
assert_true(h.has_key?(:T_FIBER)) if Object.const_defined? :Fiber
assert_equal(h[:TOTAL] * 2, h.values.reduce(:+))
h = ObjectSpace.count_objects
assert_kind_of(Hash, h)
assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
......
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