mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merges r22308 from trunk into ruby_1_9_1.
-- * hash.c (rb_hash): always return a fixnum value because a return value of rb_hash may be used as a hash value itself and bignums have no unique VALUE. * test/ruby/test_hash.rb: add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@25938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f2e6cb4f3d
commit
149d24719b
4 changed files with 36 additions and 8 deletions
|
|
@ -1,3 +1,11 @@
|
||||||
|
Sun Feb 15 03:50:21 2009 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
|
* hash.c (rb_hash): always return a fixnum value because a return
|
||||||
|
value of rb_hash may be used as a hash value itself and bignums have
|
||||||
|
no unique VALUE.
|
||||||
|
|
||||||
|
* test/ruby/test_hash.rb: add a test for above.
|
||||||
|
|
||||||
Tue Nov 17 16:04:13 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
Tue Nov 17 16:04:13 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
||||||
|
|
||||||
* regparse.c (parse_char_class): fixes a wrong merge r25531.
|
* regparse.c (parse_char_class): fixes a wrong merge r25531.
|
||||||
|
|
|
||||||
19
hash.c
19
hash.c
|
|
@ -57,7 +57,19 @@ rb_any_cmp(VALUE a, VALUE b)
|
||||||
VALUE
|
VALUE
|
||||||
rb_hash(VALUE obj)
|
rb_hash(VALUE obj)
|
||||||
{
|
{
|
||||||
return rb_funcall(obj, id_hash, 0);
|
VALUE hval = rb_funcall(obj, id_hash, 0);
|
||||||
|
retry:
|
||||||
|
switch (TYPE(hval)) {
|
||||||
|
case T_FIXNUM:
|
||||||
|
return hval;
|
||||||
|
|
||||||
|
case T_BIGNUM:
|
||||||
|
return LONG2FIX(((long*)(RBIGNUM_DIGITS(hval)))[0]);
|
||||||
|
|
||||||
|
default:
|
||||||
|
hval = rb_to_int(hval);
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -77,10 +89,7 @@ rb_any_hash(VALUE a)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
hval = rb_funcall(a, id_hash, 0);
|
hval = rb_hash(a);
|
||||||
if (!FIXNUM_P(hval)) {
|
|
||||||
hval = rb_funcall(hval, '%', 1, INT2FIX(536870923));
|
|
||||||
}
|
|
||||||
hnum = (int)FIX2LONG(hval);
|
hnum = (int)FIX2LONG(hval);
|
||||||
}
|
}
|
||||||
hnum <<= 1;
|
hnum <<= 1;
|
||||||
|
|
|
||||||
|
|
@ -851,4 +851,15 @@ class TestHash < Test::Unit::TestCase
|
||||||
def test_hash_hash
|
def test_hash_hash
|
||||||
assert_equal({0=>2,11=>1}.hash, {11=>1,0=>2}.hash)
|
assert_equal({0=>2,11=>1}.hash, {11=>1,0=>2}.hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_hash_bignum_hash
|
||||||
|
x = 2<<(32-3)-1
|
||||||
|
assert_equal({x=>1}.hash, {x=>1}.hash)
|
||||||
|
x = 2<<(64-3)-1
|
||||||
|
assert_equal({x=>1}.hash, {x=>1}.hash)
|
||||||
|
|
||||||
|
o = Object.new
|
||||||
|
def o.hash; 2<<100; end
|
||||||
|
assert_equal({x=>1}.hash, {x=>1}.hash)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
#define RUBY_VERSION "1.9.1"
|
#define RUBY_VERSION "1.9.1"
|
||||||
#define RUBY_PATCHLEVEL 339
|
#define RUBY_PATCHLEVEL 340
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
#define RUBY_VERSION_MINOR 9
|
#define RUBY_VERSION_MINOR 9
|
||||||
#define RUBY_VERSION_TEENY 1
|
#define RUBY_VERSION_TEENY 1
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2009
|
#define RUBY_RELEASE_YEAR 2009
|
||||||
#define RUBY_RELEASE_MONTH 11
|
#define RUBY_RELEASE_MONTH 11
|
||||||
#define RUBY_RELEASE_DAY 17
|
#define RUBY_RELEASE_DAY 27
|
||||||
#define RUBY_RELEASE_DATE "2009-11-17"
|
#define RUBY_RELEASE_DATE "2009-11-27"
|
||||||
|
|
||||||
#ifdef RUBY_EXTERN
|
#ifdef RUBY_EXTERN
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue