Skip to content

Commit 7d53e2b

Browse files
committed
merge revision(s) 44525,44534,44537: [Backport ruby#9381]
* hash.c (rb_objid_hash): return hash value from object ID with a salt, extract from rb_any_hash(). * object.c (rb_obj_hash): return same value as rb_any_hash(). fix r44125. [ruby-core:59638] [Bug ruby#9381] * hash.c (rb_any_hash): should treat the return value of rb_objid_hash() as `long', because ruby assumes the object id of an object is `long'. this fixes test failures on mswin64 introduced at r44525. * hash.c (rb_objid_hash): should return `long'. brushup r44534. * object.c (rb_obj_hash): follow above change. as `long', because ruby assumes the hash value of the object id of an object is `long'. git-svn-id: svn+ssh://svn.ruby-lang.org/ruby/branches/ruby_2_1@44846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent b208f1e commit 7d53e2b

5 files changed

Lines changed: 57 additions & 6 deletions

File tree

ChangeLog

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
Wed Feb 5 23:43:30 2014 NAKAMURA Usaku <usa@ruby-lang.org>
2+
3+
* hash.c (rb_objid_hash): should return `long'. brushup r44534.
4+
5+
* object.c (rb_obj_hash): follow above change.
6+
7+
Wed Feb 5 23:43:30 2014 NAKAMURA Usaku <usa@ruby-lang.org>
8+
9+
* hash.c (rb_any_hash): should treat the return value of rb_objid_hash()
10+
as `long', because ruby assumes the hash value of the object id of
11+
an object is `long'.
12+
this fixes test failures on mswin64 introduced at r44525.
13+
14+
Wed Feb 5 23:43:30 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
15+
16+
* hash.c (rb_objid_hash): return hash value from object ID with a
17+
salt, extract from rb_any_hash().
18+
19+
* object.c (rb_obj_hash): return same value as rb_any_hash().
20+
fix r44125. [ruby-core:59638] [Bug #9381]
21+
122
Wed Feb 5 22:28:41 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
223

324
* vm_insnhelper.c (vm_search_super_method): allow bound method from a

hash.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ rb_hash(VALUE obj)
123123
return hval;
124124
}
125125

126+
long rb_objid_hash(st_index_t index);
127+
126128
static st_index_t
127129
rb_any_hash(VALUE a)
128130
{
@@ -131,9 +133,7 @@ rb_any_hash(VALUE a)
131133

132134
if (SPECIAL_CONST_P(a)) {
133135
if (a == Qundef) return 0;
134-
hnum = rb_hash_start((st_index_t)a);
135-
hnum = rb_hash_uint(hnum, (st_index_t)rb_any_hash);
136-
hnum = rb_hash_end(hnum);
136+
hnum = rb_objid_hash((st_index_t)a);
137137
}
138138
else if (BUILTIN_TYPE(a) == T_STRING) {
139139
hnum = rb_str_hash(a);
@@ -146,6 +146,15 @@ rb_any_hash(VALUE a)
146146
return (st_index_t)RSHIFT(hnum, 1);
147147
}
148148

149+
long
150+
rb_objid_hash(st_index_t index)
151+
{
152+
st_index_t hnum = rb_hash_start(index);
153+
hnum = rb_hash_uint(hnum, (st_index_t)rb_any_hash);
154+
hnum = rb_hash_end(hnum);
155+
return hnum;
156+
}
157+
149158
static const struct st_hash_type objhash = {
150159
rb_any_cmp,
151160
rb_any_hash,

object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ rb_obj_equal(VALUE obj1, VALUE obj2)
161161
VALUE
162162
rb_obj_hash(VALUE obj)
163163
{
164+
long rb_objid_hash(st_index_t index);
164165
VALUE oid = rb_obj_id(obj);
165166
#if SIZEOF_LONG == SIZEOF_VOIDP
166167
st_index_t index = NUM2LONG(oid);
@@ -169,8 +170,7 @@ rb_obj_hash(VALUE obj)
169170
#else
170171
# error not supported
171172
#endif
172-
st_index_t h = rb_hash_end(rb_hash_start(index));
173-
return LONG2FIX(h);
173+
return LONG2FIX(rb_objid_hash(index));
174174
}
175175

176176
/*

test/ruby/test_hash.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,27 @@ def hash
12281228
assert_no_memory_leak([], prepare, code, bug9187)
12291229
end
12301230

1231+
def test_wrapper_of_special_const
1232+
bug9381 = '[ruby-core:59638] [Bug #9381]'
1233+
1234+
wrapper = Class.new do
1235+
def initialize(obj)
1236+
@obj = obj
1237+
end
1238+
1239+
def hash
1240+
@obj.hash
1241+
end
1242+
1243+
def eql?(other)
1244+
@obj.eql?(other)
1245+
end
1246+
end
1247+
1248+
hash = {5 => bug9381}
1249+
assert_equal(bug9381, hash[wrapper.new(5)])
1250+
end
1251+
12311252
class TestSubHash < TestHash
12321253
class SubHash < Hash
12331254
def reject(*)

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.1"
22
#define RUBY_RELEASE_DATE "2014-02-05"
3-
#define RUBY_PATCHLEVEL 21
3+
#define RUBY_PATCHLEVEL 22
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 2

0 commit comments

Comments
 (0)