diff options
author | Nobuyoshi Nakada <[email protected]> | 2019-07-03 04:12:20 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2019-07-03 04:22:41 +0900 |
commit | 796eeb6339952d92ae1b353d450c7883e589852d (patch) | |
tree | 59f8f48641492c7324de6ff2d78d7e703a3fbf91 /gc.c | |
parent | 928260c2a613bbdd4402c300e0bf86ae7562e52a (diff) |
Fix up [Feature #15974]
* Fixed warning condition
* Fixed function signature
* Use ident hash
Diffstat (limited to 'gc.c')
-rw-r--r-- | gc.c | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -2961,8 +2961,9 @@ struct should_not_capture_data { }; static void -should_not_capture_callback(const VALUE child, struct should_not_capture_data *data) +should_not_capture_callback(VALUE child, void *dp) { + struct should_not_capture_data *data = dp; if (child == data->obj) data->found = true; @@ -2970,22 +2971,20 @@ should_not_capture_callback(const VALUE child, struct should_not_capture_data *d return; // Maintain a set of objects already searched, so that we don't follow a cycle - VALUE key = rb_obj_id(child); - if (rb_hash_has_key(data->set, key)) + if (rb_hash_lookup2(data->set, child, Qfalse)) return; - rb_hash_aset(data->set, key, Qtrue); + rb_hash_aset(data->set, child, Qtrue); - rb_objspace_reachable_objects_from(child, (void (*)(unsigned long, void *)) &should_not_capture_callback, (void *)data); + rb_objspace_reachable_objects_from(child, should_not_capture_callback, data); } static void should_not_capture(VALUE block, VALUE obj) { - struct should_not_capture_data data; - data.obj = obj; - data.set = rb_hash_new(); - data.found = false; - rb_objspace_reachable_objects_from(block, (void (*)(unsigned long, void *)) &should_not_capture_callback, (void *)&data); + struct should_not_capture_data data = {obj, rb_ident_hash_new()}; + rb_obj_hide(data.set); + rb_objspace_reachable_objects_from(block, should_not_capture_callback, &data); + rb_hash_clear(data.set); if (data.found) rb_warn("object is reachable from finalizer - it may never be run"); } @@ -3019,8 +3018,9 @@ define_final(int argc, VALUE *argv, VALUE os) should_be_callable(block); } - if (ruby_verbose) + if (RTEST(ruby_verbose)) { should_not_capture(block, obj); + } return define_final0(obj, block); } |