From ede1c141c62015eb413655310f046906775b375b Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 29 Jul 2015 12:38:43 +0000 Subject: symbol.c: fix dynamic symbol hash value * hash.c (any_hash), symbol.c (dsymbol_alloc): fix dynamic symbol hash value by restricting in Fixnum range, that is `long`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51432 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ hash.c | 2 +- symbol.c | 7 +++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index c5f4fe0bae..1f4294b510 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jul 29 21:38:41 2015 Nobuyoshi Nakada + + * hash.c (any_hash), symbol.c (dsymbol_alloc): fix dynamic symbol + hash value by restricting in Fixnum range, that is `long`. + Wed Jul 29 17:25:46 2015 Nobuyoshi Nakada * hash.c (rb_obj_hash): move in order to share with rb_any_hash. diff --git a/hash.c b/hash.c index 07d88a7d66..4d5b4c63df 100644 --- a/hash.c +++ b/hash.c @@ -150,7 +150,7 @@ any_hash(VALUE a, st_index_t (*other_func)(VALUE)) hnum = rb_str_hash(a); } else if (BUILTIN_TYPE(a) == T_SYMBOL) { - return RSYMBOL(a)->hashval; + hnum = RSYMBOL(a)->hashval; } else if (BUILTIN_TYPE(a) == T_FLOAT) { flt: diff --git a/symbol.c b/symbol.c index 9e2fccd689..899ccda018 100644 --- a/symbol.c +++ b/symbol.c @@ -505,7 +505,7 @@ static VALUE dsymbol_alloc(const VALUE klass, const VALUE str, rb_encoding * const enc, const ID type) { const VALUE dsym = rb_newobj_of(klass, T_SYMBOL | FL_WB_PROTECTED); - st_index_t hashval; + long hashval; rb_enc_associate(dsym, enc); OBJ_FREEZE(dsym); @@ -513,9 +513,8 @@ dsymbol_alloc(const VALUE klass, const VALUE str, rb_encoding * const enc, const RSYMBOL(dsym)->id = type; /* we want hashval to be in Fixnum range [ruby-core:15713] r15672 */ - hashval = rb_str_hash(str); - hashval <<= 1; - RSYMBOL(dsym)->hashval = (st_index_t)RSHIFT(hashval, 1); + hashval = (long)rb_str_hash(str); + RSYMBOL(dsym)->hashval = RSHIFT((long)hashval, 1); register_sym(str, dsym); rb_hash_aset(global_symbols.dsymbol_fstr_hash, str, Qtrue); -- cgit v1.2.3