Merge pull request #2021 from take-cheeze/count_objects_total

Always increment `total` field of `os_count_struct` in callback.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-04-06 20:16:15 +09:00
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) })