diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-12 02:01:18 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-12 02:01:18 +0000 |
commit | 86e2038c273aeb76709fd1683707efd20b8c5f45 (patch) | |
tree | 8f7c7478f501e0f4cbef19a4fbd14f7de1de67ba /gc.c | |
parent | 58d50800e8a6876187c402f2fb6c3d14a9b11d78 (diff) | |
download | ruby-86e2038c273aeb76709fd1683707efd20b8c5f45.tar.gz |
gc.c: live keys only
* gc.c (wmap_keys): return keys for live objects only, like as
wmap_values.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r-- | gc.c | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -6476,7 +6476,13 @@ wmap_each_value(VALUE self) static int wmap_keys_i(st_data_t key, st_data_t val, st_data_t arg) { - rb_ary_push((VALUE)arg, (VALUE)key); + struct wmap_iter_arg *argp = (struct wmap_iter_arg *)arg; + rb_objspace_t *objspace = argp->objspace; + VALUE ary = argp->value; + VALUE obj = (VALUE)val; + if (is_id_value(objspace, obj) && is_live_object(objspace, obj)) { + rb_ary_push(ary, (VALUE)key); + } return ST_CONTINUE; } @@ -6485,12 +6491,13 @@ static VALUE wmap_keys(VALUE self) { struct weakmap *w; - VALUE ary; + struct wmap_iter_arg args; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); - ary = rb_ary_new(); - st_foreach(w->wmap2obj, wmap_keys_i, (st_data_t)ary); - return ary; + args.objspace = &rb_objspace; + args.value = rb_ary_new(); + st_foreach(w->wmap2obj, wmap_keys_i, (st_data_t)&args); + return args.value; } static int |