summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-10 14:44:51 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-10 14:44:51 +0000
commit037a9d06559e25cce2368979cecba710ddb4765d (patch)
tree0be9ec71e9ea51081b5c57f7c69495d869f92b7f /hash.c
parente5b5ee7487a55f6afd3bed90c6716a07ba0d3065 (diff)
array.c, hash.c: add salt
* array.c (rb_ary_hash): add salt to differentiate false and empty array. [ruby-core:58993] [Bug #9231] * hash.c (rb_any_hash, rb_hash_hash): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/hash.c b/hash.c
index a694477..4273aec 100644
--- a/hash.c
+++ b/hash.c
@@ -118,7 +118,9 @@ rb_any_hash(VALUE a)
if (SPECIAL_CONST_P(a)) {
if (a == Qundef) return 0;
- hnum = rb_hash_end(rb_hash_start((st_index_t)a));
+ hnum = rb_hash_start((st_index_t)a);
+ hnum = rb_hash_uint(hnum, (st_index_t)rb_any_hash);
+ hnum = rb_hash_end(hnum);
}
else if (BUILTIN_TYPE(a) == T_STRING) {
hnum = rb_str_hash(a);
@@ -1972,10 +1974,12 @@ hash_i(VALUE key, VALUE val, VALUE arg)
static VALUE
rb_hash_hash(VALUE hash)
{
- st_index_t hval = RHASH_SIZE(hash);
-
- if (!hval) return INT2FIX(0);
- rb_hash_foreach(hash, hash_i, (VALUE)&hval);
+ st_index_t size = RHASH_SIZE(hash);
+ st_index_t hval = rb_hash_start(size);
+ hval = rb_hash_uint(hval, (st_index_t)rb_hash_hash);
+ if (size) {
+ rb_hash_foreach(hash, hash_i, (VALUE)&hval);
+ }
hval = rb_hash_end(hval);
return INT2FIX(hval);
}