diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | array.c | 3 | ||||
-rw-r--r-- | bignum.c | 2 | ||||
-rw-r--r-- | compile.c | 6 | ||||
-rw-r--r-- | complex.c | 2 | ||||
-rw-r--r-- | enc/unicode.c | 8 | ||||
-rw-r--r-- | hash.c | 10 | ||||
-rw-r--r-- | include/ruby/intern.h | 4 | ||||
-rw-r--r-- | include/ruby/st.h | 8 | ||||
-rw-r--r-- | io.c | 3 | ||||
-rw-r--r-- | numeric.c | 2 | ||||
-rw-r--r-- | object.c | 2 | ||||
-rw-r--r-- | proc.c | 18 | ||||
-rw-r--r-- | range.c | 2 | ||||
-rw-r--r-- | rational.c | 2 | ||||
-rw-r--r-- | re.c | 28 | ||||
-rw-r--r-- | regparse.c | 4 | ||||
-rw-r--r-- | st.c | 18 | ||||
-rw-r--r-- | string.c | 30 | ||||
-rw-r--r-- | struct.c | 2 | ||||
-rw-r--r-- | thread.c | 13 |
21 files changed, 92 insertions, 79 deletions
@@ -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] @@ -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) { @@ -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); @@ -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); } } @@ -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 bf9984bebd..65a8da3c06 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 = { @@ -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 9ebf5d6c5e..3adec625da 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 aebdaf569d..a63364cb45 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 *); @@ -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; @@ -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 */ @@ -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); } @@ -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); } @@ -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 82122a288a..96e5266080 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); @@ -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 bb4e47af5b..9295e1d5ab 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; @@ -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; } @@ -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); } @@ -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) { @@ -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; |