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

ruby-changes:44268

From: usa <ko1@a...>
Date: Wed, 5 Oct 2016 01:25:06 +0900 (JST)
Subject: [ruby-changes:44268] usa:r56340 (trunk): * internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.

usa	2016-10-05 01:25:01 +0900 (Wed, 05 Oct 2016)

  New Revision: 56340

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

  Log:
    * internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.
      a hash value of Object might be Bignum, but it causes many troubles
      expecially the Object is used as a key of a hash.  so I've gave up
      to do so.
    
    * array.c (rb_ary_hash): use above macro.
    
    * bignum.c (rb_big_hash): ditto.
    
    * hash.c (rb_obj_hash, rb_hash_hash): ditto.
    
    * numeric.c (rb_dbl_hash): ditto.
    
    * proc.c (proc_hash): ditto.
    
    * re.c (rb_reg_hash, match_hash): ditto.
    
    * string.c (rb_str_hash_m): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/bignum.c
    trunk/hash.c
    trunk/internal.h
    trunk/numeric.c
    trunk/proc.c
    trunk/re.c
    trunk/string.c
Index: proc.c
===================================================================
--- proc.c	(revision 56339)
+++ proc.c	(revision 56340)
@@ -1196,7 +1196,7 @@ proc_hash(VALUE self) https://github.com/ruby/ruby/blob/trunk/proc.c#L1196
     hash = rb_hash_start(0);
     hash = rb_hash_proc(hash, self);
     hash = rb_hash_end(hash);
-    return LONG2FIX(hash);
+    return ST2FIX(hash);
 }
 
 /*
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56339)
+++ ChangeLog	(revision 56340)
@@ -1,3 +1,24 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Oct  5 01:19:45 2016  NAKAMURA Usaku  <usa@r...>
+
+	* internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.
+	  a hash value of Object might be Bignum, but it causes many troubles
+	  expecially the Object is used as a key of a hash.  so I've gave up
+	  to do so.
+
+	* array.c (rb_ary_hash): use above macro.
+
+	* bignum.c (rb_big_hash): ditto.
+
+	* hash.c (rb_obj_hash, rb_hash_hash): ditto.
+
+	* numeric.c (rb_dbl_hash): ditto.
+
+	* proc.c (proc_hash): ditto.
+
+	* re.c (rb_reg_hash, match_hash): ditto.
+
+	* string.c (rb_str_hash_m): ditto.
+
 Tue Oct  4 12:59:44 2016  Koichi ITO  <koic.ito@g...>
 
 	* array.c (rb_ary_dig): [DOC] update an example of error message
Index: hash.c
===================================================================
--- hash.c	(revision 56339)
+++ hash.c	(revision 56340)
@@ -239,7 +239,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/hash.c#L239
 rb_obj_hash(VALUE obj)
 {
     st_index_t hnum = any_hash(obj, objid_hash);
-    return LONG2FIX(hnum);
+    return ST2FIX(hnum);
 }
 
 int
@@ -2277,7 +2277,7 @@ rb_hash_hash(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L2277
 	rb_hash_foreach(hash, hash_i, (VALUE)&hval);
     }
     hval = rb_hash_end(hval);
-    return INT2FIX(hval);
+    return ST2FIX(hval);
 }
 
 static int
Index: re.c
===================================================================
--- re.c	(revision 56339)
+++ re.c	(revision 56340)
@@ -2888,7 +2888,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/re.c#L2888
 rb_reg_hash(VALUE re)
 {
     st_index_t hashval = reg_hash(re);
-    return LONG2FIX(hashval);
+    return ST2FIX(hashval);
 }
 
 static st_index_t
@@ -2956,7 +2956,7 @@ match_hash(VALUE match) https://github.com/ruby/ruby/blob/trunk/re.c#L2956
     hashval = rb_hash_uint(hashval, rb_memhash(regs->beg, regs->num_regs * sizeof(*regs->beg)));
     hashval = rb_hash_uint(hashval, rb_memhash(regs->end, regs->num_regs * sizeof(*regs->end)));
     hashval = rb_hash_end(hashval);
-    return LONG2FIX(hashval);
+    return ST2FIX(hashval);
 }
 
 /*
Index: internal.h
===================================================================
--- internal.h	(revision 56339)
+++ internal.h	(revision 56340)
@@ -323,6 +323,9 @@ ntz_intptr(uintptr_t x) { https://github.com/ruby/ruby/blob/trunk/internal.h#L323
 VALUE rb_int128t2big(int128_t n);
 #endif
 
+#define ST2FIX(h) LONG2FIX((long)(h))
+
+
 /* arguments must be Fixnum */
 static inline VALUE
 rb_fix_mul_fix(VALUE x, VALUE y)
Index: string.c
===================================================================
--- string.c	(revision 56339)
+++ string.c	(revision 56340)
@@ -2963,13 +2963,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L2963
 rb_str_hash_m(VALUE str)
 {
     st_index_t hval = rb_str_hash(str);
-#if SIZEOF_LONG == SIZEOF_VOIDP
-    return LONG2FIX((long)hval);
-#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
-    return LL2NUM((LONG_LONG)hval);
-#else
-# error unsupported platform
-#endif
+    return ST2FIX(hval);
 }
 
 #define lesser(a,b) (((a)>(b))?(b):(a))
Index: array.c
===================================================================
--- array.c	(revision 56339)
+++ array.c	(revision 56340)
@@ -3927,7 +3927,7 @@ rb_ary_hash(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L3927
 	h = rb_hash_uint(h, NUM2LONG(n));
     }
     h = rb_hash_end(h);
-    return LONG2FIX(h);
+    return ST2FIX(h);
 }
 
 /*
Index: numeric.c
===================================================================
--- numeric.c	(revision 56339)
+++ numeric.c	(revision 56340)
@@ -1355,7 +1355,7 @@ rb_dbl_hash(double d) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1355
     /* normalize -0.0 to 0.0 */
     if (d == 0.0) d = 0.0;
     hash = rb_memhash(&d, sizeof(d));
-    return LONG2FIX(hash);
+    return ST2FIX(hash);
 }
 
 VALUE
Index: bignum.c
===================================================================
--- bignum.c	(revision 56339)
+++ bignum.c	(revision 56340)
@@ -6645,7 +6645,7 @@ rb_big_hash(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6645
     st_index_t hash;
 
     hash = rb_memhash(BDIGITS(x), sizeof(BDIGIT)*BIGNUM_LEN(x)) ^ BIGNUM_SIGN(x);
-    return INT2FIX(hash);
+    return ST2FIX(hash);
 }
 
 /*

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

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