On Feb 21, 2006, at 9:21 PM, Eric Hodel wrote:

> On Feb 5, 2006, at 5:05 AM, Mauricio Fernandez wrote:
>> Another possibility would be that the address space for the data  
>> segment
>> used in OSX is lower than on Linux, so the SYM2ID matches an existent
>> symbol:
>>
>> RUBY_PLATFORM                                      # => "i686-linux"
>> Object.new.inspect                                 # => "#<Object: 
>> 0xb7d44d7c>"
>> 0xb7d44d7c >> 9                                    # => 6023718
>> # we shouldn't have 6 million symbols
>> 0x1d421c >> 9                                      # => 3745
>> # but 4000 are indeed possible
>
> If you're close enough to the beginning of memory  
> ObjectSpace#_id2ref will pick a Symbol over the real object like  
> you mention above:

Here's an even simpler example:

$ cat overlap.rb
#!/usr/local/bin/ruby -w

last = Symbol.all_symbols.sort_by { |s| s.object_id }.last
puts "last symbol: %p (0x%x)" % [last, last.object_id]

os = Array.new 1000

1000.times { |i| os[i] = Object.new }

1000.times do |i|
   o = os[i]
   next unless o.object_id & 0xff == 0x0e
   o2 = ObjectSpace._id2ref o.object_id
   puts "mismatch at object %d (0x%x)!" % [i, o.object_id] unless  
o.equal? o2
end
$ ruby -v overlap.rb
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.4.0]
last symbol: :o2 (0x27090e)
mismatch at object 43 (0xe2d0e)!
mismatch at object 555 (0xe190e)!
mismatch at object 683 (0xe140e)!
-- 
Eric Hodel - drbrain / segment7.net - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com