ruby-changes:32767
From: naruse <ko1@a...>
Date: Wed, 5 Feb 2014 23:53:54 +0900 (JST)
Subject: [ruby-changes:32767] naruse:r44846 (ruby_2_1): merge revision(s) 44525, 44534, 44537: [Backport #9381]
naruse 2014-02-05 23:53:48 +0900 (Wed, 05 Feb 2014) New Revision: 44846 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44846 Log: merge revision(s) 44525,44534,44537: [Backport #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 #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'. Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/hash.c branches/ruby_2_1/object.c branches/ruby_2_1/test/ruby/test_hash.rb branches/ruby_2_1/version.h Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 44845) +++ ruby_2_1/ChangeLog (revision 44846) @@ -1,3 +1,24 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Wed Feb 5 23:43:30 2014 NAKAMURA Usaku <usa@r...> + + * hash.c (rb_objid_hash): should return `long'. brushup r44534. + + * object.c (rb_obj_hash): follow above change. + +Wed Feb 5 23:43:30 2014 NAKAMURA Usaku <usa@r...> + + * hash.c (rb_any_hash): should treat the return value of rb_objid_hash() + as `long', because ruby assumes the hash value of the object id of + an object is `long'. + this fixes test failures on mswin64 introduced at r44525. + +Wed Feb 5 23:43:30 2014 Nobuyoshi Nakada <nobu@r...> + + * 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 #9381] + Wed Feb 5 22:28:41 2014 Nobuyoshi Nakada <nobu@r...> * vm_insnhelper.c (vm_search_super_method): allow bound method from a Index: ruby_2_1/object.c =================================================================== --- ruby_2_1/object.c (revision 44845) +++ ruby_2_1/object.c (revision 44846) @@ -161,6 +161,7 @@ rb_obj_equal(VALUE obj1, VALUE obj2) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/object.c#L161 VALUE rb_obj_hash(VALUE obj) { + long rb_objid_hash(st_index_t index); VALUE oid = rb_obj_id(obj); #if SIZEOF_LONG == SIZEOF_VOIDP st_index_t index = NUM2LONG(oid); @@ -169,8 +170,7 @@ rb_obj_hash(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/object.c#L170 #else # error not supported #endif - st_index_t h = rb_hash_end(rb_hash_start(index)); - return LONG2FIX(h); + return LONG2FIX(rb_objid_hash(index)); } /* Index: ruby_2_1/hash.c =================================================================== --- ruby_2_1/hash.c (revision 44845) +++ ruby_2_1/hash.c (revision 44846) @@ -123,6 +123,8 @@ rb_hash(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/hash.c#L123 return hval; } +long rb_objid_hash(st_index_t index); + static st_index_t rb_any_hash(VALUE a) { @@ -131,9 +133,7 @@ rb_any_hash(VALUE a) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/hash.c#L133 if (SPECIAL_CONST_P(a)) { if (a == Qundef) return 0; - hnum = rb_hash_start((st_index_t)a); - hnum = rb_hash_uint(hnum, (st_index_t)rb_any_hash); - hnum = rb_hash_end(hnum); + hnum = rb_objid_hash((st_index_t)a); } else if (BUILTIN_TYPE(a) == T_STRING) { hnum = rb_str_hash(a); @@ -146,6 +146,15 @@ rb_any_hash(VALUE a) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/hash.c#L146 return (st_index_t)RSHIFT(hnum, 1); } +long +rb_objid_hash(st_index_t index) +{ + st_index_t hnum = rb_hash_start(index); + hnum = rb_hash_uint(hnum, (st_index_t)rb_any_hash); + hnum = rb_hash_end(hnum); + return hnum; +} + static const struct st_hash_type objhash = { rb_any_cmp, rb_any_hash, Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 44845) +++ ruby_2_1/version.h (revision 44846) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.1" #define RUBY_RELEASE_DATE "2014-02-05" -#define RUBY_PATCHLEVEL 21 +#define RUBY_PATCHLEVEL 22 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 2 Index: ruby_2_1/test/ruby/test_hash.rb =================================================================== --- ruby_2_1/test/ruby/test_hash.rb (revision 44845) +++ ruby_2_1/test/ruby/test_hash.rb (revision 44846) @@ -1228,6 +1228,27 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_hash.rb#L1228 assert_no_memory_leak([], prepare, code, bug9187) end + def test_wrapper_of_special_const + bug9381 = '[ruby-core:59638] [Bug #9381]' + + wrapper = Class.new do + def initialize(obj) + @obj = obj + end + + def hash + @obj.hash + end + + def eql?(other) + @obj.eql?(other) + end + end + + hash = {5 => bug9381} + assert_equal(bug9381, hash[wrapper.new(5)]) + end + class TestSubHash < TestHash class SubHash < Hash def reject(*) Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r44525,44534,44537 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/