ruby-changes:29195
From: nobu <ko1@a...>
Date: Wed, 12 Jun 2013 12:04:55 +0900 (JST)
Subject: [ruby-changes:29195] nobu:r41247 (trunk): array.c: freeze in callback
nobu 2013-06-12 12:04:11 +0900 (Wed, 12 Jun 2013) New Revision: 41247 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41247 Log: array.c: freeze in callback * array.c (rb_ary_uniq_bang): must not be modified once frozen even in a callback method. Modified files: trunk/ChangeLog trunk/array.c trunk/test/ruby/test_array.rb Index: array.c =================================================================== --- array.c (revision 41246) +++ array.c (revision 41247) @@ -3981,6 +3981,7 @@ rb_ary_uniq_bang(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L3981 if (RARRAY_LEN(ary) == (i = RHASH_SIZE(hash))) { return Qnil; } + rb_ary_modify(ary); ARY_SET_LEN(ary, 0); if (ARY_SHARED_P(ary) && !ARY_EMBED_P(ary)) { rb_ary_unshare(ary); Index: ChangeLog =================================================================== --- ChangeLog (revision 41246) +++ ChangeLog (revision 41247) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jun 12 12:04:09 2013 Nobuyoshi Nakada <nobu@r...> + + * array.c (rb_ary_uniq_bang): must not be modified once frozen even in + a callback method. + Wed Jun 12 12:03:43 2013 Nobuyoshi Nakada <nobu@r...> * array.c (rb_ary_sort_bang): must not be modified once frozen even in Index: test/ruby/test_array.rb =================================================================== --- test/ruby/test_array.rb (revision 41246) +++ test/ruby/test_array.rb (revision 41247) @@ -1569,6 +1569,15 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L1569 assert_equal(nil, b) end + def test_uniq_bang_with_freeze + ary = [1,2] + orig = ary.dup + assert_raise(RuntimeError, "frozen during comparison") { + ary.uniq! {|v| ary.freeze; 1} + } + assert_equal(orig, ary, "must not be modified once frozen") + end + def test_unshift a = @cls[] assert_equal(@cls['cat'], a.unshift('cat')) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/