aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog21
-rw-r--r--array.c2
-rw-r--r--bignum.c2
-rw-r--r--hash.c4
-rw-r--r--internal.h3
-rw-r--r--numeric.c2
-rw-r--r--proc.c2
-rw-r--r--re.c4
-rw-r--r--string.c8
9 files changed, 33 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 7511b2e855..b6e5dbbad6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+Wed Oct 5 01:19:45 2016 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * 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@gmail.com>
* array.c (rb_ary_dig): [DOC] update an example of error message
diff --git a/array.c b/array.c
index d24f071d27..c742c4fc70 100644
--- a/array.c
+++ b/array.c
@@ -3927,7 +3927,7 @@ rb_ary_hash(VALUE ary)
h = rb_hash_uint(h, NUM2LONG(n));
}
h = rb_hash_end(h);
- return LONG2FIX(h);
+ return ST2FIX(h);
}
/*
diff --git a/bignum.c b/bignum.c
index ca06c54b3e..dbfe89967c 100644
--- a/bignum.c
+++ b/bignum.c
@@ -6645,7 +6645,7 @@ rb_big_hash(VALUE x)
st_index_t hash;
hash = rb_memhash(BDIGITS(x), sizeof(BDIGIT)*BIGNUM_LEN(x)) ^ BIGNUM_SIGN(x);
- return INT2FIX(hash);
+ return ST2FIX(hash);
}
/*
diff --git a/hash.c b/hash.c
index 1bc93ea92c..2f2b1f169e 100644
--- a/hash.c
+++ b/hash.c
@@ -239,7 +239,7 @@ VALUE
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)
rb_hash_foreach(hash, hash_i, (VALUE)&hval);
}
hval = rb_hash_end(hval);
- return INT2FIX(hval);
+ return ST2FIX(hval);
}
static int
diff --git a/internal.h b/internal.h
index 54e5d3bc78..de435ac16b 100644
--- a/internal.h
+++ b/internal.h
@@ -323,6 +323,9 @@ ntz_intptr(uintptr_t x) {
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)
diff --git a/numeric.c b/numeric.c
index 9ce86e1a59..e288119318 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1355,7 +1355,7 @@ rb_dbl_hash(double d)
/* 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
diff --git a/proc.c b/proc.c
index e39fd0528d..126932e8f0 100644
--- a/proc.c
+++ b/proc.c
@@ -1196,7 +1196,7 @@ proc_hash(VALUE self)
hash = rb_hash_start(0);
hash = rb_hash_proc(hash, self);
hash = rb_hash_end(hash);
- return LONG2FIX(hash);
+ return ST2FIX(hash);
}
/*
diff --git a/re.c b/re.c
index 6fd086a1bd..2f3149a85c 100644
--- a/re.c
+++ b/re.c
@@ -2888,7 +2888,7 @@ static VALUE
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)
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);
}
/*
diff --git a/string.c b/string.c
index 57b4e9ac15..56f1432bde 100644
--- a/string.c
+++ b/string.c
@@ -2963,13 +2963,7 @@ static VALUE
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))