New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Ticket #22361 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

Ruby 1.87 Hash equivalence fails on large Fixnums

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

Description (last modified by macsforever2000@…) (diff)

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

comment:1 Changed 4 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 4 years ago by visnupx@…

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

comment:3 Changed 4 years ago by macsforever2000@…

  • Keywords ruby hash removed
  • Owner changed from macports-tickets@… to kimuraw@…
  • Port set to ruby

comment:4 Changed 4 years ago by macsforever2000@…

  • Description modified (diff)

comment:5 Changed 4 years ago by visnupx@…

  • Cc visnupx@… added

Cc Me!

comment:6 Changed 4 years ago by kimuraw@…

  • Status changed from new to assigned

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 4 years ago by kimuraw@…

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 4 years ago by kimuraw@…

  • Status changed from assigned to closed
  • Resolution set to fixed

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.