Project

General

Profile

Bug #9381

2.1.0 Regression. Hash lookup with #hash and #eql?

Added by nick78 (Nick S) almost 5 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
[ruby-core:59638]

Description

Ruby 2.1.0 won't fetch objects when the lookup key overrides #hash and #eql?.
This is a regression as it works as expected in ruby 1.8, 1.9 and 2.0.

class Wrapper
  def initialize(obj)
    @obj = obj
  end

  def method_missing(symbol, *args, &block)
    @obj.__send__(symbol, *args, &block)
  end

  def hash
    @obj.hash
  end

  def eql?(other)
    @obj.eql?(other)
  end
end

hash = { 5 => "LOOKUP SUCCEEDED" }

# Prints "LOOKUP SUCCEEDED" on RUBY < 2.1.0. Fails on RUBY 2.1.0.
p hash[Wrapper.new(5)]

Associated revisions

Revision ab6efa5b
Added by nobu (Nobuyoshi Nakada) almost 5 years ago

object.c: hash value from objid with salt

  • 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. [Bug #9381]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 44525
Added by nobu (Nobuyoshi Nakada) almost 5 years ago

object.c: hash value from objid with salt

  • 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. [Bug #9381]

Revision 44525
Added by nobu (Nobuyoshi Nakada) almost 5 years ago

object.c: hash value from objid with salt

  • 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. [Bug #9381]

Revision 44525
Added by nobu (Nobuyoshi Nakada) almost 5 years ago

object.c: hash value from objid with salt

  • 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. [Bug #9381]

Revision 44525
Added by nobu (Nobuyoshi Nakada) almost 5 years ago

object.c: hash value from objid with salt

  • 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. [Bug #9381]

Revision 44525
Added by nobu (Nobuyoshi Nakada) almost 5 years ago

object.c: hash value from objid with salt

  • 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. [Bug #9381]

Revision 72d18038
Added by naruse (Yui NARUSE) over 4 years ago

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.   [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'.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@44846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 4de35baf
Added by nobu (Nobuyoshi Nakada) about 3 years ago

test_hash.rb: add assertions

  • test/ruby/test_hash.rb (test_wrapper_of_special_const): test other special obejcts. [Bug #9381]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 51423
Added by nobu (Nobuyoshi Nakada) about 3 years ago

test_hash.rb: add assertions

  • test/ruby/test_hash.rb (test_wrapper_of_special_const): test other special obejcts. [Bug #9381]

Revision 51423
Added by nobu (Nobuyoshi Nakada) about 3 years ago

test_hash.rb: add assertions

  • test/ruby/test_hash.rb (test_wrapper_of_special_const): test other special obejcts. [Bug #9381]

Revision 51423
Added by nobu (Nobuyoshi Nakada) about 3 years ago

test_hash.rb: add assertions

  • test/ruby/test_hash.rb (test_wrapper_of_special_const): test other special obejcts. [Bug #9381]

Revision 51423
Added by nobu (Nobuyoshi Nakada) about 3 years ago

test_hash.rb: add assertions

  • test/ruby/test_hash.rb (test_wrapper_of_special_const): test other special obejcts. [Bug #9381]

Revision efc7a3a7
Added by nobu (Nobuyoshi Nakada) about 3 years ago

hash.c: fix float hash

  • hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a Fixnum, but not a long. [Bug #9381]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 51425
Added by nobu (Nobuyoshi Nakada) about 3 years ago

hash.c: fix float hash

  • hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a Fixnum, but not a long. [Bug #9381]

Revision 51425
Added by nobu (Nobuyoshi Nakada) about 3 years ago

hash.c: fix float hash

  • hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a Fixnum, but not a long. [Bug #9381]

Revision 51425
Added by nobu (Nobuyoshi Nakada) about 3 years ago

hash.c: fix float hash

  • hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a Fixnum, but not a long. [Bug #9381]

Revision 51425
Added by nobu (Nobuyoshi Nakada) about 3 years ago

hash.c: fix float hash

  • hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a Fixnum, but not a long. [Bug #9381]

Revision 48f9012d
Added by nobu (Nobuyoshi Nakada) about 3 years ago

hash.c: fix symbol hash

  • hash.c (rb_sym_hash): return same value as rb_any_hash() of Symbol. [Bug #9381]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 51426
Added by nobu (Nobuyoshi Nakada) about 3 years ago

hash.c: fix symbol hash

  • hash.c (rb_sym_hash): return same value as rb_any_hash() of Symbol. [Bug #9381]

Revision 51426
Added by nobu (Nobuyoshi Nakada) about 3 years ago

hash.c: fix symbol hash

  • hash.c (rb_sym_hash): return same value as rb_any_hash() of Symbol. [Bug #9381]

Revision 51426
Added by nobu (Nobuyoshi Nakada) about 3 years ago

hash.c: fix symbol hash

  • hash.c (rb_sym_hash): return same value as rb_any_hash() of Symbol. [Bug #9381]

Revision 51426
Added by nobu (Nobuyoshi Nakada) about 3 years ago

hash.c: fix symbol hash

  • hash.c (rb_sym_hash): return same value as rb_any_hash() of Symbol. [Bug #9381]

Revision 640c135c
Added by nagachika (Tomoyuki Chikanaga) about 3 years ago

merge revision(s) 51423,51425: [Backport #9381]

test_hash.rb: add assertions

* test/ruby/test_hash.rb (test_wrapper_of_special_const): test

other special obejcts. [Bug #9381]
* hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a
Fixnum, but not a long. [Bug #9381]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@51572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 51572
Added by nagachika (Tomoyuki Chikanaga) about 3 years ago

merge revision(s) 51423,51425: [Backport #9381]

test_hash.rb: add assertions

* test/ruby/test_hash.rb (test_wrapper_of_special_const): test

other special obejcts. [Bug #9381]
* hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a
Fixnum, but not a long. [Bug #9381]

Revision 170f64d6
Added by usa (Usaku NAKAMURA) about 3 years ago

merge revision(s) 51423,51425: [Backport #9381]

test_hash.rb: add assertions

* test/ruby/test_hash.rb (test_wrapper_of_special_const): test

other special obejcts. [Bug #9381]
* hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a
Fixnum, but not a long. [Bug #9381]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@51613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 51613
Added by usa (Usaku NAKAMURA) about 3 years ago

merge revision(s) 51423,51425: [Backport #9381]

test_hash.rb: add assertions

* test/ruby/test_hash.rb (test_wrapper_of_special_const): test

other special obejcts. [Bug #9381]
* hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a
Fixnum, but not a long. [Bug #9381]

History

#1 [ruby-core:59639] Updated by nobu (Nobuyoshi Nakada) almost 5 years ago

  • Description updated (diff)
  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)
  • Target version set to 2.2.0
  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED

#2 Updated by nobu (Nobuyoshi Nakada) almost 5 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r44525.
Nick, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


object.c: hash value from objid with salt

  • 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. [Bug #9381]

#3 [ruby-core:60880] Updated by naruse (Yui NARUSE) over 4 years ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: DONE

#4 [ruby-core:60927] Updated by nobu (Nobuyoshi Nakada) over 4 years ago

  • Description updated (diff)

#5 [ruby-core:70171] Updated by nagachika (Tomoyuki Chikanaga) about 3 years ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: DONE to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED, 2.2: REQUIRED

I re-fill Backport field for r51425. I'm not sure if this is bugfix or feature change though.

#6 Updated by nagachika (Tomoyuki Chikanaga) about 3 years ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED, 2.2: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED, 2.2: DONE

I additionally backport r51425 into ruby_2_2 branch at r51572.

#7 Updated by usa (Usaku NAKAMURA) about 3 years ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED, 2.2: DONE to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: DONE, 2.2: DONE

ruby_2_1 r51613 merged revision(s) 51423,51425.

Also available in: Atom PDF