Opened 14 years ago

Closed 14 years ago

#22361 closed defect (fixed)

Ruby 1.87 Hash equivalence fails on large Fixnums

Reported by: ben@… Owned by: kimuraw (kimura wataru)
Priority: Normal Milestone:
Component: ports Version: 1.8.1
Keywords: Cc: visnupx@…
Port: ruby

Description (last modified by mf2k (Frank Schima))

On MacOS Leopard 10.5.8 with Ruby 1.87 (all patchlevels <= 174) and all compatible versions of MacPorts (<= 1.8.1)

Hash equivalence fails when a value is a Fixnum > 536870911.

>> {:a => 536870911}.hash == {:a => 536870911}.hash
=> true
>> {:a => 536870912}.hash == {:a => 536870912}.hash
=> false

Change History (8)

comment:1 Changed 14 years ago by visnupx@…

btw, 229 == 536870912. also, works on snow leopard:

>> {:a => 2**29-1}.hash
=> 2146753031
>> {:a => 2**29-1}.hash
=> 2146753031
>> {:a => 2**29}.hash
=> -2146753029
>> {:a => 2**29}.hash
=> -2146753029

comment:2 Changed 14 years ago by visnupx@…

apple's /usr/bin/ruby in snow leopard 10.6.1

comment:3 Changed 14 years ago by mf2k (Frank Schima)

Keywords: ruby hash removed
Owner: changed from macports-tickets@… to kimuraw@…
Port: ruby added

comment:4 Changed 14 years ago by mf2k (Frank Schima)

Description: modified (diff)

comment:5 Changed 14 years ago by visnupx@…

Cc: visnupx@… added

Cc Me!

comment:6 Changed 14 years ago by kimuraw (kimura wataru)

Status: newassigned

I reproduced this on snow leopard built-in ruby.

  % arch -x86_64 /usr/bin/ruby -e 'p ({:a=>2**61}.hash == {:a=>2**61}.hash)'
  false
  % arch -i386 /usr/bin/ruby -e 'p ({:a=>2**29}.hash == {:a=>2**29}.hash)'  
  false

comment:7 Changed 14 years ago by kimuraw (kimura wataru)

Hash#hash returns different values from each invocations.

% ruby -v 
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10]
% irb --simple-prompt
>> h = {:a => 2**61} 
=> {:a=>2305843009213693952}
>> h.hash
=> 3933384
>> h.hash
=> 4179968

I think this is a problem of ruby. I filed a ticket for redmine.ruby-lang.org (in japanese).

http://redmine.ruby-lang.org/issues/show/2334

comment:8 Changed 14 years ago by kimuraw (kimura wataru)

Resolution: fixed
Status: assignedclosed

ruby core team solved this issue.

I made a patch from ruby-1.8 changes and added the patch to port:ruby at r60220. the latest port:ruby (1.8.7-p174_1) works fine.

Note: See TracTickets for help on using tickets.