summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--array.c3
-rw-r--r--bignum.c2
-rw-r--r--compile.c6
-rw-r--r--complex.c2
-rw-r--r--enc/unicode.c8
-rw-r--r--hash.c10
-rw-r--r--include/ruby/intern.h4
-rw-r--r--include/ruby/st.h8
-rw-r--r--io.c3
-rw-r--r--numeric.c2
-rw-r--r--object.c2
-rw-r--r--proc.c18
-rw-r--r--range.c2
-rw-r--r--rational.c2
-rw-r--r--re.c28
-rw-r--r--regparse.c4
-rw-r--r--st.c18
-rw-r--r--string.c30
-rw-r--r--struct.c2
-rw-r--r--thread.c13
21 files changed, 92 insertions, 79 deletions
diff --git a/ChangeLog b/ChangeLog
index 1256244..bdfa4ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Sep 8 22:10:02 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * include/ruby/st.h (st_hash_func): use st_index_t.
+
Tue Sep 8 21:48:15 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm.c (rb_thread_mark): mark callers iseqs. [ruby-core:25474]
diff --git a/array.c b/array.c
index b6a8900..d16cccb 100644
--- a/array.c
+++ b/array.c
@@ -2880,7 +2880,8 @@ rb_ary_eql(VALUE ary1, VALUE ary2)
static VALUE
recursive_hash(VALUE ary, VALUE dummy, int recur)
{
- long i, h;
+ long i;
+ st_index_t h;
VALUE n;
if (recur) {
diff --git a/bignum.c b/bignum.c
index a2ce0bc..23d0ecf 100644
--- a/bignum.c
+++ b/bignum.c
@@ -3143,7 +3143,7 @@ rb_big_aref(VALUE x, VALUE y)
static VALUE
rb_big_hash(VALUE x)
{
- int hash;
+ st_index_t hash;
hash = rb_memhash(BDIGITS(x), sizeof(BDIGIT)*RBIGNUM_LEN(x)) ^ RBIGNUM_SIGN(x);
return INT2FIX(hash);
diff --git a/compile.c b/compile.c
index d3c2667..3999e69 100644
--- a/compile.c
+++ b/compile.c
@@ -1233,14 +1233,14 @@ cdhash_cmp(VALUE val, VALUE lit)
return !rb_eql(lit, val);
}
-static int
+static st_index_t
cdhash_hash(VALUE a)
{
- if (SPECIAL_CONST_P(a)) return (int)a;
+ if (SPECIAL_CONST_P(a)) return (st_index_t)a;
if (TYPE(a) == T_STRING) return rb_str_hash(a);
{
VALUE hval = rb_hash(a);
- return (int)FIX2LONG(hval);
+ return (st_index_t)FIX2LONG(hval);
}
}
diff --git a/complex.c b/complex.c
index 19d0c3c..0a4f4aa 100644
--- a/complex.c
+++ b/complex.c
@@ -1156,7 +1156,7 @@ nucomp_numerator(VALUE self)
static VALUE
nucomp_hash(VALUE self)
{
- long v, h[2];
+ st_index_t v, h[2];
VALUE n;
get_dat1(self);
diff --git a/enc/unicode.c b/enc/unicode.c
index bf9984b..65a8da3 100644
--- a/enc/unicode.c
+++ b/enc/unicode.c
@@ -2122,10 +2122,10 @@ code2_cmp(OnigCodePoint* x, OnigCodePoint* y)
return 1;
}
-static int
+static st_index_t
code2_hash(OnigCodePoint* x)
{
- return (int )(x[0] + x[1]);
+ return (st_index_t )(x[0] + x[1]);
}
static const struct st_hash_type type_code2_hash = {
@@ -2140,10 +2140,10 @@ code3_cmp(OnigCodePoint* x, OnigCodePoint* y)
return 1;
}
-static int
+static st_index_t
code3_hash(OnigCodePoint* x)
{
- return (int )(x[0] + x[1] + x[2]);
+ return (st_index_t )(x[0] + x[1] + x[2]);
}
static const struct st_hash_type type_code3_hash = {
diff --git a/hash.c b/hash.c
index ce8af6c..bc0a251 100644
--- a/hash.c
+++ b/hash.c
@@ -72,11 +72,11 @@ rb_hash(VALUE obj)
}
}
-static int
+static st_index_t
rb_any_hash(VALUE a)
{
VALUE hval;
- VALUE hnum;
+ st_index_t hnum;
switch (TYPE(a)) {
case T_FIXNUM:
@@ -96,7 +96,7 @@ rb_any_hash(VALUE a)
hnum = FIX2LONG(hval);
}
hnum <<= 1;
- return (int)RSHIFT(hnum, 1);
+ return (st_index_t)RSHIFT(hnum, 1);
}
static const struct st_hash_type objhash = {
@@ -1544,7 +1544,7 @@ rb_hash_eql(VALUE hash1, VALUE hash2)
static int
hash_i(VALUE key, VALUE val, VALUE arg)
{
- VALUE *hval = (VALUE *)arg;
+ st_index_t *hval = (st_index_t *)arg;
if (key == Qundef) return ST_CONTINUE;
*hval ^= rb_hash_end(rb_hash_uint(rb_hash_start(rb_hash(key)), rb_hash(val)));
@@ -1554,7 +1554,7 @@ hash_i(VALUE key, VALUE val, VALUE arg)
static VALUE
recursive_hash(VALUE hash, VALUE dummy, int recur)
{
- VALUE hval;
+ st_index_t hval;
if (recur) {
rb_raise(rb_eArgError, "recursive key for hash");
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index 9ebf5d6..3adec62 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -633,12 +633,12 @@ VALUE rb_str_cat(VALUE, const char*, long);
VALUE rb_str_cat2(VALUE, const char*);
VALUE rb_str_append(VALUE, VALUE);
VALUE rb_str_concat(VALUE, VALUE);
-int rb_memhash(const void *ptr, long len);
+st_index_t rb_memhash(const void *ptr, long len);
VALUE rb_hash_start(VALUE);
VALUE rb_hash_uint32(VALUE, unsigned int);
VALUE rb_hash_uint(VALUE, VALUE);
VALUE rb_hash_end(VALUE);
-int rb_str_hash(VALUE);
+st_index_t rb_str_hash(VALUE);
int rb_str_hash_cmp(VALUE,VALUE);
int rb_str_comparable(VALUE, VALUE);
int rb_str_cmp(VALUE, VALUE);
diff --git a/include/ruby/st.h b/include/ruby/st.h
index aebdaf5..a63364c 100644
--- a/include/ruby/st.h
+++ b/include/ruby/st.h
@@ -55,15 +55,15 @@ typedef unsigned LONG_LONG st_data_t;
typedef struct st_table st_table;
+typedef st_data_t st_index_t;
typedef int st_compare_func(st_data_t, st_data_t);
-typedef int st_hash_func(st_data_t);
+typedef st_index_t st_hash_func(st_data_t);
struct st_hash_type {
int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */
- int (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */
+ st_index_t (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */
};
-typedef st_data_t st_index_t;
#define ST_INDEX_BITS (sizeof(st_index_t) * CHAR_BIT)
struct st_table {
@@ -104,7 +104,7 @@ void st_cleanup_safe(st_table *, st_data_t);
void st_clear(st_table *);
st_table *st_copy(st_table *);
int st_numcmp(st_data_t, st_data_t);
-int st_numhash(st_data_t);
+st_index_t st_numhash(st_data_t);
int st_strcasecmp(const char *s1, const char *s2);
int st_strncasecmp(const char *s1, const char *s2, size_t n);
size_t st_memsize(st_table *);
diff --git a/io.c b/io.c
index 1e6b26b..90fa233 100644
--- a/io.c
+++ b/io.c
@@ -6750,6 +6750,7 @@ static VALUE
argf_getline(int argc, VALUE *argv, VALUE argf)
{
VALUE line;
+ int lineno = ARGF.lineno;
retry:
if (!next_argv()) return Qnil;
@@ -6770,7 +6771,7 @@ argf_getline(int argc, VALUE *argv, VALUE argf)
}
}
if (!NIL_P(line)) {
- ARGF.lineno++;
+ ARGF.lineno = ++lineno;
ARGF.last_lineno = ARGF.lineno;
}
return line;
diff --git a/numeric.c b/numeric.c
index e16b95c..6460278 100644
--- a/numeric.c
+++ b/numeric.c
@@ -936,7 +936,7 @@ static VALUE
flo_hash(VALUE num)
{
double d;
- int hash;
+ st_index_t hash;
d = RFLOAT_VALUE(num);
/* normalize -0.0 to 0.0 */
diff --git a/object.c b/object.c
index 78dbcdc..156d358 100644
--- a/object.c
+++ b/object.c
@@ -99,7 +99,7 @@ VALUE
rb_obj_hash(VALUE obj)
{
VALUE oid = rb_obj_id(obj);
- unsigned long h = rb_hash_end(rb_hash_start(NUM2LONG(oid)));
+ st_index_t h = rb_hash_end(rb_hash_start(NUM2LONG(oid)));
return LONG2NUM(h);
}
diff --git a/proc.c b/proc.c
index 39a6697..710de39 100644
--- a/proc.c
+++ b/proc.c
@@ -771,12 +771,13 @@ proc_eq(VALUE self, VALUE other)
static VALUE
proc_hash(VALUE self)
{
- long hash;
+ st_index_t hash;
rb_proc_t *proc;
GetProcPtr(self, proc);
- hash = (long)proc->block.iseq;
- hash ^= (long)proc->envval;
- hash ^= (long)proc->block.lfp >> 16;
+ hash = rb_hash_start((st_index_t)proc->block.iseq);
+ hash = rb_hash_uint(hash, (st_index_t)proc->envval);
+ hash = rb_hash_uint(hash, (st_index_t)proc->block.lfp >> 16);
+ hash = rb_hash_end(hash);
return LONG2FIX(hash);
}
@@ -993,12 +994,13 @@ static VALUE
method_hash(VALUE method)
{
struct METHOD *m;
- long hash;
+ st_index_t hash;
TypedData_Get_Struct(method, struct METHOD, &method_data_type, m);
- hash = (long)m->rclass;
- hash ^= (long)m->recv;
- hash ^= (long)m->me.def;
+ hash = rb_hash_start((st_index_t)m->rclass);
+ hash = rb_hash_uint(hash, (st_index_t)m->recv);
+ hash = rb_hash_uint(hash, (st_index_t)m->me.def);
+ hash = rb_hash_end(hash);
return INT2FIX(hash);
}
diff --git a/range.c b/range.c
index d1f90f4..7398315 100644
--- a/range.c
+++ b/range.c
@@ -204,7 +204,7 @@ range_eql(VALUE range, VALUE obj)
static VALUE
recursive_hash(VALUE range, VALUE dummy, int recur)
{
- unsigned long hash = EXCL(range);
+ st_index_t hash = EXCL(range);
VALUE v;
if (recur) {
diff --git a/rational.c b/rational.c
index 82122a2..96e5266 100644
--- a/rational.c
+++ b/rational.c
@@ -1495,7 +1495,7 @@ nurat_rationalize(int argc, VALUE *argv, VALUE self)
static VALUE
nurat_hash(VALUE self)
{
- long v, h[2];
+ st_index_t v, h[2];
VALUE n;
get_dat1(self);
diff --git a/re.c b/re.c
index 1197481..c75c5b3 100644
--- a/re.c
+++ b/re.c
@@ -2485,6 +2485,7 @@ rb_reg_regcomp(VALUE str)
return reg_cache = rb_reg_new_str(save_str, 0);
}
+static st_index_t reg_hash(VALUE re);
/*
* call-seq:
* rxp.hash => fixnum
@@ -2495,20 +2496,19 @@ rb_reg_regcomp(VALUE str)
static VALUE
rb_reg_hash(VALUE re)
{
- unsigned long hashval;
- long len;
- char *p;
+ st_index_t hashval;
+ return LONG2FIX(hashval);
+}
+
+static st_index_t
+reg_hash(VALUE re)
+{
+ st_index_t hashval;
rb_reg_check(re);
hashval = RREGEXP(re)->ptr->options;
- len = RREGEXP_SRC_LEN(re);
- p = RREGEXP_SRC_PTR(re);
- while (len--) {
- hashval = hashval * 33 + *p++;
- }
- hashval = hashval + (hashval>>5);
-
- return LONG2FIX(hashval);
+ hashval = rb_hash_uint(hashval, rb_memhash(RREGEXP_SRC_PTR(re), RREGEXP_SRC_LEN(re)));
+ return rb_hash_end(hashval);
}
@@ -2555,11 +2555,9 @@ static VALUE
match_hash(VALUE match)
{
const struct re_registers *regs;
- VALUE h;
- unsigned long hashval = rb_hash_start(rb_str_hash(RMATCH(match)->str));
+ st_index_t hashval = rb_hash_start(rb_str_hash(RMATCH(match)->str));
- h = rb_reg_hash(RMATCH(match)->regexp);
- rb_hash_uint(hashval, FIX2LONG(h));
+ rb_hash_uint(hashval, reg_hash(RMATCH(match)->regexp));
regs = RMATCH_REGS(match);
hashval = rb_hash_uint(hashval, regs->num_regs);
hashval = rb_hash_uint(hashval, rb_memhash(regs->beg, regs->num_regs * sizeof(*regs->beg)));
diff --git a/regparse.c b/regparse.c
index bb4e47a..9295e1d 100644
--- a/regparse.c
+++ b/regparse.c
@@ -335,7 +335,7 @@ str_end_cmp(st_str_end_key* x, st_str_end_key* y)
return 0;
}
-static int
+static st_index_t
str_end_hash(st_str_end_key* x)
{
UChar *p;
@@ -4937,7 +4937,7 @@ static int type_cclass_cmp(type_cclass_key* x, type_cclass_key* y)
return 0;
}
-static int type_cclass_hash(type_cclass_key* key)
+static st_index_t type_cclass_hash(type_cclass_key* key)
{
int i, val;
UChar *p;
diff --git a/st.c b/st.c
index 7866d03..938e07d 100644
--- a/st.c
+++ b/st.c
@@ -44,13 +44,13 @@ static const struct st_hash_type type_numhash = {
};
/* extern int strcmp(const char *, const char *); */
-static int strhash(const char *);
+static st_index_t strhash(const char *);
static const struct st_hash_type type_strhash = {
strcmp,
strhash,
};
-static int strcasehash(const char *);
+static st_index_t strcasehash(const char *);
static const struct st_hash_type type_strcasehash = {
st_strcasecmp,
strcasehash,
@@ -69,7 +69,7 @@ static void rehash(st_table *);
#define EQUAL(table,x,y) ((x)==(y) || (*table->type->compare)((x),(y)) == 0)
-#define do_hash(key,table) (unsigned int)(*(table)->type->hash)((key))
+#define do_hash(key,table) (unsigned int)(st_index_t)(*(table)->type->hash)((key))
#define do_hash_bin(key,table) (do_hash(key, table)%(table)->num_bins)
/*
@@ -927,10 +927,10 @@ st_reverse_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
*/
#define FNV_32_PRIME 0x01000193
-static int
+static st_index_t
strhash(register const char *string)
{
- register unsigned int hval = FNV1_32A_INIT;
+ register st_index_t hval = FNV1_32A_INIT;
/*
* FNV-1a hash each octet in the buffer
@@ -994,10 +994,10 @@ st_strncasecmp(const char *s1, const char *s2, size_t n)
return 0;
}
-static int
+static st_index_t
strcasehash(register const char *string)
{
- register unsigned int hval = FNV1_32A_INIT;
+ register st_index_t hval = FNV1_32A_INIT;
/*
* FNV-1a hash each octet in the buffer
@@ -1019,8 +1019,8 @@ st_numcmp(st_data_t x, st_data_t y)
return x != y;
}
-int
+st_index_t
st_numhash(st_data_t n)
{
- return (int)n;
+ return (st_index_t)n;
}
diff --git a/string.c b/string.c
index c5e16e0..aa36c37 100644
--- a/string.c
+++ b/string.c
@@ -2026,8 +2026,8 @@ murmur_finish(unsigned long h)
#define murmur_step(h, k) murmur(h, k, 16)
-static VALUE
-hash(const unsigned char * data, size_t len, VALUE h)
+static st_index_t
+hash(const unsigned char * data, size_t len, st_index_t h)
{
uint32_t t = 0;
@@ -2150,14 +2150,14 @@ hash(const unsigned char * data, size_t len, VALUE h)
return murmur_finish(h);
}
-VALUE
-rb_hash_uint32(VALUE h, unsigned int i)
+st_index_t
+rb_hash_uint32(st_index_t h, unsigned int i)
{
return murmur_step(h + i, 16);
}
-VALUE
-rb_hash_uint(VALUE h, VALUE i)
+st_index_t
+rb_hash_uint(st_index_t h, st_index_t i)
{
unsigned long v = 0;
h += i;
@@ -2187,16 +2187,16 @@ rb_hash_uint(VALUE h, VALUE i)
return v;
}
-VALUE
-rb_hash_end(VALUE h)
+st_index_t
+rb_hash_end(st_index_t h)
{
h = murmur_step(h, 10);
h = murmur_step(h, 17);
return h;
}
-VALUE
-rb_hash_start(VALUE h)
+st_index_t
+rb_hash_start(st_index_t h)
{
static int hashseed_init = 0;
static VALUE hashseed;
@@ -2221,20 +2221,20 @@ rb_hash_start(VALUE h)
return hashseed + h;
}
-int
+st_index_t
rb_memhash(const void *ptr, long len)
{
- return (int)hash(ptr, len, rb_hash_start(0));
+ return hash(ptr, len, rb_hash_start(0));
}
-int
+st_index_t
rb_str_hash(VALUE str)
{
int e = ENCODING_GET(str);
if (e && rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT) {
e = 0;
}
- return (int)rb_memhash((const void *)RSTRING_PTR(str), RSTRING_LEN(str)) ^ e;
+ return rb_memhash((const void *)RSTRING_PTR(str), RSTRING_LEN(str)) ^ e;
}
int
@@ -2260,7 +2260,7 @@ rb_str_hash_cmp(VALUE str1, VALUE str2)
static VALUE
rb_str_hash_m(VALUE str)
{
- int hval = rb_str_hash(str);
+ st_index_t hval = rb_str_hash(str);
return INT2FIX(hval);
}
diff --git a/struct.c b/struct.c
index e87ddda..463fa39 100644
--- a/struct.c
+++ b/struct.c
@@ -807,7 +807,7 @@ static VALUE
recursive_hash(VALUE s, VALUE dummy, int recur)
{
long i;
- unsigned long h;
+ st_index_t h;
VALUE n;
if (recur) {
diff --git a/thread.c b/thread.c
index 05d129d..c7a334f 100644
--- a/thread.c
+++ b/thread.c
@@ -2356,6 +2356,11 @@ do_select(int n, fd_set *read, fd_set *write, fd_set *except,
{
int result, lerrno;
fd_set orig_read, orig_write, orig_except;
+#if defined __GNUC__ && defined __x86_64__
+#define FAKE_FD_ZERO(f) (*(int *)&(f)=0) /* suppress lots of warnings */
+#else
+#define FAKE_FD_ZERO(f) ((void)0)
+#endif
#ifndef linux
double limit = 0;
@@ -2377,9 +2382,11 @@ do_select(int n, fd_set *read, fd_set *write, fd_set *except,
}
#endif
- if (read) orig_read = *read;
- if (write) orig_write = *write;
- if (except) orig_except = *except;
+ if (read) orig_read = *read; else FAKE_FD_ZERO(orig_read);
+ if (write) orig_write = *write; else FAKE_FD_ZERO(orig_write);
+ if (except) orig_except = *except; else FAKE_FD_ZERO(orig_except);
+
+#undef FAKE_FD_ZERO
retry:
lerrno = 0;