1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* gc.c (count_objects): clear given hash.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-05-31 14:03:23 +00:00
parent c6bac86887
commit fa58f951cf
3 changed files with 22 additions and 0 deletions

View file

@ -1,3 +1,7 @@
Sat May 31 23:02:00 2008 Tanaka Akira <akr@fsij.org>
* gc.c (count_objects): clear given hash.
Sat May 31 20:28:10 2008 Yusuke Endoh <mame@tsg.ne.jp>
* test/ruby/test_regexp.rb: add tests.

12
gc.c
View file

@ -2239,6 +2239,15 @@ rb_obj_id(VALUE obj)
return (VALUE)((SIGNED_VALUE)obj|FIXNUM_FLAG);
}
static int
set_zero(st_data_t key, st_data_t val, st_data_t arg)
{
VALUE k = (VALUE)key;
VALUE hash = (VALUE)arg;
rb_hash_aset(hash, k, INT2FIX(0));
return ST_CONTINUE;
}
/*
* call-seq:
* ObjectSpace.count_objects([result_hash]) -> hash
@ -2272,6 +2281,9 @@ count_objects(int argc, VALUE *argv, VALUE os)
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
if (TYPE(hash) != T_HASH)
rb_raise(rb_eTypeError, "non-hash given");
if (!RHASH_EMPTY_P(hash)) {
st_foreach(RHASH_TBL(hash), set_zero, hash);
}
}
for (i = 0; i <= T_MASK; i++) {

View file

@ -47,5 +47,11 @@ End
assert(h.values.all? {|x| x.is_a?(Integer) })
assert_raise(TypeError) { ObjectSpace.count_objects(1) }
h0 = {:T_FOO=>1000}
h = ObjectSpace.count_objects(h0)
p h0.equal?(h)
assert_same(h0, h)
assert_equal(0, h0[:T_FOO])
end
end