[前][次][番号順一覧][スレッド一覧]

ruby-changes:39351

From: nobu <ko1@a...>
Date: Wed, 29 Jul 2015 21:38:57 +0900 (JST)
Subject: [ruby-changes:39351] nobu:r51432 (trunk): symbol.c: fix dynamic symbol hash value

nobu	2015-07-29 21:38:43 +0900 (Wed, 29 Jul 2015)

  New Revision: 51432

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51432

  Log:
    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`.

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/symbol.c
Index: symbol.c
===================================================================
--- symbol.c	(revision 51431)
+++ symbol.c	(revision 51432)
@@ -505,7 +505,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/symbol.c#L505
 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 V https://github.com/ruby/ruby/blob/trunk/symbol.c#L513
     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);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51431)
+++ ChangeLog	(revision 51432)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 29 21:38:41 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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  <nobu@r...>
 
 	* hash.c (rb_obj_hash): move in order to share with rb_any_hash.
Index: hash.c
===================================================================
--- hash.c	(revision 51431)
+++ hash.c	(revision 51432)
@@ -150,7 +150,7 @@ any_hash(VALUE a, st_index_t (*other_fun https://github.com/ruby/ruby/blob/trunk/hash.c#L150
 	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:

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]