hash.c: fix symbol hash
* hash.c (rb_sym_hash): return same value as rb_any_hash() of Symbol. [Bug #9381] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
efc7a3a712
commit
48f9012df9
@ -1,4 +1,7 @@
|
|||||||
Wed Jul 29 14:53:32 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Jul 29 14:54:16 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* hash.c (rb_sym_hash): return same value as rb_any_hash() of
|
||||||
|
Symbol. [Bug #9381]
|
||||||
|
|
||||||
* hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a
|
* hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a
|
||||||
Fixnum, but not a long. [Bug #9381]
|
Fixnum, but not a long. [Bug #9381]
|
||||||
|
15
hash.c
15
hash.c
@ -129,6 +129,21 @@ rb_hash(VALUE obj)
|
|||||||
|
|
||||||
long rb_objid_hash(st_index_t index);
|
long rb_objid_hash(st_index_t index);
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
rb_sym_hash(VALUE sym)
|
||||||
|
{
|
||||||
|
st_index_t hnum;
|
||||||
|
|
||||||
|
if (STATIC_SYM_P(sym)) {
|
||||||
|
sym >>= (RUBY_SPECIAL_SHIFT + ID_SCOPE_SHIFT);
|
||||||
|
hnum = rb_objid_hash((st_index_t)sym);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
hnum = RSYMBOL(sym)->hashval;
|
||||||
|
}
|
||||||
|
return LONG2FIX(hnum);
|
||||||
|
}
|
||||||
|
|
||||||
static st_index_t
|
static st_index_t
|
||||||
rb_any_hash(VALUE a)
|
rb_any_hash(VALUE a)
|
||||||
{
|
{
|
||||||
|
3
string.c
3
string.c
@ -9149,6 +9149,8 @@ rb_to_symbol(VALUE name)
|
|||||||
return rb_str_intern(name);
|
return rb_str_intern(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE rb_sym_hash(VALUE);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A <code>String</code> object holds and manipulates an arbitrary sequence of
|
* A <code>String</code> object holds and manipulates an arbitrary sequence of
|
||||||
* bytes, typically representing characters. String objects may be created
|
* bytes, typically representing characters. String objects may be created
|
||||||
@ -9311,6 +9313,7 @@ Init_String(void)
|
|||||||
rb_undef_method(CLASS_OF(rb_cSymbol), "new");
|
rb_undef_method(CLASS_OF(rb_cSymbol), "new");
|
||||||
rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0); /* in symbol.c */
|
rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0); /* in symbol.c */
|
||||||
|
|
||||||
|
rb_define_method(rb_cSymbol, "hash", rb_sym_hash, 0); /* in hash.c */
|
||||||
rb_define_method(rb_cSymbol, "==", sym_equal, 1);
|
rb_define_method(rb_cSymbol, "==", sym_equal, 1);
|
||||||
rb_define_method(rb_cSymbol, "===", sym_equal, 1);
|
rb_define_method(rb_cSymbol, "===", sym_equal, 1);
|
||||||
rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0);
|
rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0);
|
||||||
|
@ -1282,6 +1282,7 @@ class TestHash < Test::Unit::TestCase
|
|||||||
bad = [
|
bad = [
|
||||||
5, true, false, nil,
|
5, true, false, nil,
|
||||||
0.0, 1.72723e-77,
|
0.0, 1.72723e-77,
|
||||||
|
:foo, "dsym_#{self.object_id.to_s(16)}_#{Time.now.to_i.to_s(16)}".to_sym,
|
||||||
].select do |x|
|
].select do |x|
|
||||||
hash = {x => bug9381}
|
hash = {x => bug9381}
|
||||||
hash[wrapper.new(x)] != bug9381
|
hash[wrapper.new(x)] != bug9381
|
||||||
|
Loading…
x
Reference in New Issue
Block a user