aboutsummaryrefslogtreecommitdiffstats
path: root/enum.c
diff options
context:
space:
mode:
authorKenichi Kamiya <kachick1@gmail.com>2021-03-27 12:55:46 +0900
committerGitHub <noreply@github.com>2021-03-27 12:55:46 +0900
commitaceb8c0b4bf37a65c78f09eaf835db72c7a47c48 (patch)
tree02baafb15b9aa9fb1c45670932a25e1138a006f9 /enum.c
parent785c77d7827677b547fa233deef0b65ec10ecf6b (diff)
downloadruby-aceb8c0b4bf37a65c78f09eaf835db72c7a47c48.tar.gz
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
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c10
1 files changed, 7 insertions, 3 deletions
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);
}