Project

General

Profile

Bug #9202

Array#uniq freezes duplicate strings

Added by Eric Hodel over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
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}

0001-Array-uniq-uniq-does-not-return-frozen-hash-keys.patch View (3.68 KB) Eric Wong, 12/03/2013 12:10 PM

Associated revisions

Revision 43969
Added by glass over 2 years ago

  • array.c (ary_add_hash): set and return values because string keys
    will be frozen. [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).

Revision 43969
Added by glass over 2 years ago

  • array.c (ary_add_hash): set and return values because string keys
    will be frozen. [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).

Revision 43969
Added by glass over 2 years ago

  • array.c (ary_add_hash): set and return values because string keys
    will be frozen. [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).

History

#1 [ruby-core:58810] Updated by Eric Hodel over 2 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]

#2 [ruby-core:58812] Updated by Eric Wong over 2 years ago

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

#3 [ruby-core:58814] Updated by Eric Wong over 2 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.

#4 [ruby-core:58816] Updated by Eric Wong over 2 years ago

This should fix it, can you confirm/? Thanks

#5 [ruby-core:58825] Updated by Masaki Matsushita over 2 years ago

  • Assignee changed from Charlie Somerville to Masaki Matsushita

I confirmed it. Thank you for your patch!

#6 Updated by Anonymous over 2 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. [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).

#7 [ruby-core:58840] Updated by Eric Wong over 2 years ago

"Glass_saga (Masaki Matsushita)" glass.saga@gmail.com 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.

Also available in: Atom PDF