summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-01-11 23:14:58 -0800
committerGitHub <noreply@github.com>2023-01-11 23:14:58 -0800
commitd4a3882c1c184e483d6a06f5e4417f01d30da88d (patch)
tree00fd4b287fcc52068054b52c64b0328d86db8ec8 /hash.c
parenta8537eae2abf307ec22446d617900796741520a8 (diff)
downloadruby-d4a3882c1c184e483d6a06f5e4417f01d30da88d.tar.gz
Assert possible hash functions in RHASH_ST_TABLE (#7107)
Because of the function pointer, it's hard to figure out what hash functions could be used in Hash objects when st_lookup is used. Having this assertion makes it easier to understand what hash_stlike_lookup could possibly do. (AR uses only rb_any_hash) For example, this clarifies that hash_stlike_lookup never calls a #hash method when a key is T_STRING or T_SYMBOL.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 5204d8b018..2b243d9e66 100644
--- a/hash.c
+++ b/hash.c
@@ -2110,6 +2110,10 @@ hash_stlike_lookup(VALUE hash, st_data_t key, st_data_t *pval)
return ar_lookup(hash, key, pval);
}
else {
+ extern st_index_t rb_iseq_cdhash_hash(VALUE);
+ RUBY_ASSERT(RHASH_ST_TABLE(hash)->type->hash == rb_any_hash ||
+ RHASH_ST_TABLE(hash)->type->hash == rb_ident_hash ||
+ RHASH_ST_TABLE(hash)->type->hash == rb_iseq_cdhash_hash);
return st_lookup(RHASH_ST_TABLE(hash), key, pval);
}
}