ruby-changes:13046
From: nobu <ko1@a...>
Date: Tue, 8 Sep 2009 22:10:27 +0900 (JST)
Subject: [ruby-changes:13046] Ruby:r24792 (trunk): * include/ruby/st.h (st_hash_func): use st_index_t.
nobu 2009-09-08 22:10:04 +0900 (Tue, 08 Sep 2009) New Revision: 24792 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24792 Log: * include/ruby/st.h (st_hash_func): use st_index_t. Modified files: trunk/ChangeLog trunk/array.c trunk/bignum.c trunk/compile.c trunk/complex.c trunk/enc/unicode.c trunk/hash.c trunk/include/ruby/intern.h trunk/include/ruby/st.h trunk/io.c trunk/numeric.c trunk/object.c trunk/proc.c trunk/range.c trunk/rational.c trunk/re.c trunk/regparse.c trunk/st.c trunk/string.c trunk/struct.c trunk/thread.c Index: complex.c =================================================================== --- complex.c (revision 24791) +++ complex.c (revision 24792) @@ -1156,7 +1156,7 @@ static VALUE nucomp_hash(VALUE self) { - long v, h[2]; + st_index_t v, h[2]; VALUE n; get_dat1(self); Index: regparse.c =================================================================== --- regparse.c (revision 24791) +++ regparse.c (revision 24792) @@ -335,7 +335,7 @@ return 0; } -static int +static st_index_t str_end_hash(st_str_end_key* x) { UChar *p; @@ -4937,7 +4937,7 @@ 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; Index: array.c =================================================================== --- array.c (revision 24791) +++ array.c (revision 24792) @@ -2880,7 +2880,8 @@ static VALUE recursive_hash(VALUE ary, VALUE dummy, int recur) { - long i, h; + long i; + st_index_t h; VALUE n; if (recur) { Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 24791) +++ include/ruby/intern.h (revision 24792) @@ -633,12 +633,12 @@ 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); Index: include/ruby/st.h =================================================================== --- include/ruby/st.h (revision 24791) +++ include/ruby/st.h (revision 24792) @@ -55,15 +55,15 @@ 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_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 *); Index: ChangeLog =================================================================== --- ChangeLog (revision 24791) +++ ChangeLog (revision 24792) @@ -1,3 +1,7 @@ +Tue Sep 8 22:10:02 2009 Nobuyoshi Nakada <nobu@r...> + + * include/ruby/st.h (st_hash_func): use st_index_t. + Tue Sep 8 21:48:15 2009 Nobuyoshi Nakada <nobu@r...> * vm.c (rb_thread_mark): mark callers iseqs. [ruby-core:25474] Index: re.c =================================================================== --- re.c (revision 24791) +++ re.c (revision 24792) @@ -2485,6 +2485,7 @@ 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 @@ 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 @@ 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))); Index: enc/unicode.c =================================================================== --- enc/unicode.c (revision 24791) +++ enc/unicode.c (revision 24792) @@ -2122,10 +2122,10 @@ 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 @@ 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 = { Index: string.c =================================================================== --- string.c (revision 24791) +++ string.c (revision 24792) @@ -2026,8 +2026,8 @@ #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 @@ 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 @@ 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 @@ 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 @@ 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); } Index: object.c =================================================================== --- object.c (revision 24791) +++ object.c (revision 24792) @@ -99,7 +99,7 @@ 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); } Index: io.c =================================================================== --- io.c (revision 24791) +++ io.c (revision 24792) @@ -6750,6 +6750,7 @@ argf_getline(int argc, VALUE *argv, VALUE argf) { VALUE line; + int lineno = ARGF.lineno; retry: if (!next_argv()) return Qnil; @@ -6770,7 +6771,7 @@ } } if (!NIL_P(line)) { - ARGF.lineno++; + ARGF.lineno = ++lineno; ARGF.last_lineno = ARGF.lineno; } return line; Index: st.c =================================================================== --- st.c (revision 24791) +++ st.c (revision 24792) @@ -44,13 +44,13 @@ }; /* 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 @@ #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 @@ */ #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 @@ 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 @@ return x != y; } -int +st_index_t st_numhash(st_data_t n) { - return (int)n; + return (st_index_t)n; } Index: compile.c =================================================================== --- compile.c (revision 24791) +++ compile.c (revision 24792) @@ -1233,14 +1233,14 @@ 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); } } Index: range.c =================================================================== --- range.c (revision 24791) +++ range.c (revision 24792) @@ -204,7 +204,7 @@ 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) { Index: proc.c =================================================================== --- proc.c (revision 24791) +++ proc.c (revision 24792) @@ -771,12 +771,13 @@ 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 @@ 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); } Index: thread.c =================================================================== --- thread.c (revision 24791) +++ thread.c (revision 24792) @@ -2356,6 +2356,11 @@ { 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,10 +2382,12 @@ } #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; Index: struct.c =================================================================== --- struct.c (revision 24791) +++ struct.c (revision 24792) @@ -807,7 +807,7 @@ recursive_hash(VALUE s, VALUE dummy, int recur) { long i; - unsigned long h; + st_index_t h; VALUE n; if (recur) { Index: hash.c =================================================================== --- hash.c (revision 24791) +++ hash.c (revision 24792) @@ -72,11 +72,11 @@ } } -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 @@ 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 @@ 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 @@ 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"); Index: numeric.c =================================================================== --- numeric.c (revision 24791) +++ numeric.c (revision 24792) @@ -936,7 +936,7 @@ flo_hash(VALUE num) { double d; - int hash; + st_index_t hash; d = RFLOAT_VALUE(num); /* normalize -0.0 to 0.0 */ Index: bignum.c =================================================================== --- bignum.c (revision 24791) +++ bignum.c (revision 24792) @@ -3143,7 +3143,7 @@ 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); Index: rational.c =================================================================== --- rational.c (revision 24791) +++ rational.c (revision 24792) @@ -1495,7 +1495,7 @@ static VALUE nurat_hash(VALUE self) { - long v, h[2]; + st_index_t v, h[2]; VALUE n; get_dat1(self); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/