diff options
author | Koichi Sasada <[email protected]> | 2022-02-16 11:07:45 +0900 |
---|---|---|
committer | Koichi Sasada <[email protected]> | 2022-02-16 13:31:46 +0900 |
commit | 1ae630db2682831cc0f2d381ff46e7b8cd3c2174 () | |
tree | 42810e54fd0a086b0160c33cba0fba96db6c5d77 | |
parent | 26187a8520b8c6645206a2064c11a7ab86a89845 (diff) |
`wmap#each` should check liveness of keys
`ObjectSpace::WeakMap#each*` should check key's liveness. fix [Bug #18586]
Notes: Merged: https://.com/ruby/ruby/pull/5556
-rw-r--r-- | gc.c | 62 |
1 files changed, 42 insertions, 20 deletions
@@ -12428,15 +12428,24 @@ wmap_inspect(VALUE self) return str; } static int wmap_each_i(st_data_t key, st_data_t val, st_data_t arg) { rb_objspace_t *objspace = (rb_objspace_t *)arg; - VALUE obj = (VALUE)val; - if (wmap_live_p(objspace, obj)) { - rb_yield_values(2, (VALUE)key, obj); } - return ST_CONTINUE; } /* Iterates over keys and objects in a weakly referenced object */ @@ -12455,11 +12464,14 @@ static int wmap_each_key_i(st_data_t key, st_data_t val, st_data_t arg) { rb_objspace_t *objspace = (rb_objspace_t *)arg; - VALUE obj = (VALUE)val; - if (wmap_live_p(objspace, obj)) { - rb_yield((VALUE)key); } - return ST_CONTINUE; } /* Iterates over keys and objects in a weakly referenced object */ @@ -12478,11 +12490,14 @@ static int wmap_each_value_i(st_data_t key, st_data_t val, st_data_t arg) { rb_objspace_t *objspace = (rb_objspace_t *)arg; - VALUE obj = (VALUE)val; - if (wmap_live_p(objspace, obj)) { - rb_yield(obj); } - return ST_CONTINUE; } /* Iterates over keys and objects in a weakly referenced object */ @@ -12503,11 +12518,14 @@ wmap_keys_i(st_data_t key, st_data_t val, st_data_t arg) 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 (wmap_live_p(objspace, obj)) { - rb_ary_push(ary, (VALUE)key); } - return ST_CONTINUE; } /* Iterates over keys and objects in a weakly referenced object */ @@ -12530,11 +12548,14 @@ wmap_values_i(st_data_t key, st_data_t val, st_data_t arg) 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 (wmap_live_p(objspace, obj)) { - rb_ary_push(ary, obj); } - return ST_CONTINUE; } /* Iterates over values and objects in a weakly referenced object */ @@ -12599,6 +12620,7 @@ wmap_lookup(VALUE self, VALUE key) VALUE obj; struct weakmap *w; rb_objspace_t *objspace = &rb_objspace; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); if (!st_lookup(w->wmap2obj, (st_data_t)key, &data)) return Qundef; |