Project

General

Profile

Actions

Bug #9202

closed

Array#uniq freezes duplicate strings

Added by drbrain (Eric Hodel) almost 11 years ago. Updated almost 11 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 2.1.0dev (2013-12-02 trunk 43958) [x86_64-darwin13.0]
[ruby-core:58809]

Description

I imagine this is related to the recent frozen string changes. This behavior change in Array#uniq breaks RubyGems:

$ cat test.rb
p unique: %w[a].uniq.any? { |item| item.frozen? }
p duplicate: %w[a a].uniq.any? { |item| item.frozen? }
$ ruby -v test.rb
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
{:unique=>false}
{:duplicate=>false}
$ make runruby
./miniruby -I../trunk/lib -I. -I.ext/common ../trunk/tool/runruby.rb --extout=.ext -- --disable-gems ../trunk/test.rb
{:unique=>false}
{:duplicate=>true}


Files

Updated by drbrain (Eric Hodel) almost 11 years ago

  • ruby -v changed from ruby 2.0.0dev (2012-11-29 trunk 37968) [x86_64-darwin12.2.0] to ruby 2.1.0dev (2013-12-02 trunk 43958) [x86_64-darwin13.0]

Updated by normalperson (Eric Wong) almost 11 years ago

It's not r43870 (Use rb_fstring() to de-duplicate hash string keys)
Bisecting now...

Updated by normalperson (Eric Wong) almost 11 years ago

bisected to r43194:

 * array.c (rb_ary_uniq): use rb_hash_keys().

 * internal.h: define rb_hash_keys() as internal API.

 * hash.c (rb_hash_keys): ditto.

Updated by Glass_saga (Masaki Matsushita) almost 11 years ago

  • Assignee changed from Anonymous to Glass_saga (Masaki Matsushita)

I confirmed it. Thank you for your patch!

Actions #6

Updated by Anonymous almost 11 years ago

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

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


  • array.c (ary_add_hash): set and return values because string keys
    will be frozen. [ruby-core:58809] [Bug #9202]

  • array.c (rb_ary_uniq_bang): ditto.

  • array.c (rb_ary_or): ditto.

  • array.c (rb_ary_uniq): ditto.

  • test/ruby/test_array.rb: tests for above.

The patch is from normalperson (Eric Wong).

Updated by normalperson (Eric Wong) almost 11 years ago

"Glass_saga (Masaki Matsushita)" wrote:

I confirmed it. Thank you for your patch!

No problem, thanks for the review.

Also, I think we may remove rb_hash_keys from internal.h and make it
static again.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0