From aceb8c0b4bf37a65c78f09eaf835db72c7a47c48 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Sat, 27 Mar 2021 12:55:46 +0900 Subject: Fix Enumerable#tally with some arguments pattern [Feature #17744] * Add test cases for Enumerable#tally with hash argument * Add ruby/spec for Enumerable#tally with hash argument * Fix Enumerable#tally does not update given frozen hash * Add test cases for Enumerable#tally with hash convertible arguments * Fix SEGV when Enumerable#tally takes non Hash convertible * FIx cosmetic damage enum.c --- enum.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'enum.c') diff --git a/enum.c b/enum.c index c7828cdb01..b3a8f9e1d8 100644 --- a/enum.c +++ b/enum.c @@ -1069,10 +1069,14 @@ static VALUE enum_tally(int argc, VALUE *argv, VALUE obj) { VALUE hash; - if (rb_check_arity(argc, 0, 1)) - hash = rb_check_hash_type(argv[0]); - else + if (rb_check_arity(argc, 0, 1)) { + hash = rb_convert_type(argv[0], T_HASH, "Hash", "to_hash"); + rb_check_frozen(hash); + } + else { hash = rb_hash_new(); + } + return enum_hashify_into(obj, 0, 0, tally_i, hash); } -- cgit v1.2.3