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.)
This commit is contained in:
take_cheeze
2014-04-06 18:13:29 +09:00
parent 63dc51c2f9
commit c4f14755a7
2 changed files with 4 additions and 1 deletions
@@ -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) })