From 03a7970e953df23ce4b6c4debb5e2cfe1182dc21 Mon Sep 17 00:00:00 2001 From: yugui Date: Mon, 28 Mar 2011 13:40:50 +0000 Subject: merges r30736,r30738 and r30739 from trunk into ruby_1_9_2. -- * array.c (rb_ary_uniq_bang): call ARY_SET_LEN(ary, 0) before rb_resize_capa because rb_resize_capa expects resized length is smaller than current array length. call rb_ary_unshare before rb_resize_capa because rb_resize_capa losts the reference to original shared array. -- Add ML Reference and a test for r30736 [ruby-core:34997] -- Additional fix for r30736 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@31200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ array.c | 6 +++++- test/ruby/test_array.rb | 6 ++++++ version.h | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 858e53b25a..c9295e47b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Mon Jan 31 04:45:12 2011 NARUSE, Yui + + * array.c (rb_ary_uniq_bang): call ARY_SET_LEN(ary, 0) before + rb_resize_capa because rb_resize_capa expects resized length is + smaller than current array length. call rb_ary_unshare before + rb_resize_capa because rb_resize_capa losts the reference to + original shared array. [ruby-core:34997] + Sun Jan 30 16:15:20 2011 Nobuyoshi Nakada * test/dl/test_dl2.rb (TestDL#test_sin): math functions do not diff --git a/array.c b/array.c index 6640a1af28..60f3f5646b 100644 --- a/array.c +++ b/array.c @@ -3430,8 +3430,12 @@ rb_ary_uniq_bang(VALUE ary) if (RARRAY_LEN(ary) == (i = RHASH_SIZE(hash))) { return Qnil; } - ary_resize_capa(ary, i); ARY_SET_LEN(ary, 0); + if (ARY_SHARED_P(ary) && !ARY_EMBED_P(ary)) { + rb_ary_unshare(ary); + FL_SET_EMBED(ary); + } + ary_resize_capa(ary, i); st_foreach(RHASH_TBL(hash), push_value, ary); } else { diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 1c80f2d145..6170e916ac 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -1456,6 +1456,12 @@ class TestArray < Test::Unit::TestCase assert_raise(ArgumentError) { a.uniq!(1) } assert_raise(ArgumentError) { f.uniq!(1) } assert_raise(RuntimeError) { f.uniq! } + + assert_nothing_raised do + a = [ {c: "b"}, {c: "r"}, {c: "w"}, {c: "g"}, {c: "g"} ] + a.sort_by!{|e| e[:c]} + a.uniq! {|e| e[:c]} + end end def test_uniq_bang_with_block diff --git a/version.h b/version.h index ef94c7d258..c3946aa95c 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_PATCHLEVEL 183 +#define RUBY_PATCHLEVEL 184 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 -- cgit v1.2.3