1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

array.c: freeze in callback

* array.c (rb_ary_uniq_bang): must not be modified once frozen even in
  a callback method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-06-12 03:04:11 +00:00
parent da786437a7
commit 7fa5e608d3
3 changed files with 15 additions and 0 deletions

View file

@ -1,3 +1,8 @@
Wed Jun 12 12:04:09 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org>
* array.c (rb_ary_sort_bang): must not be modified once frozen even in

View file

@ -3981,6 +3981,7 @@ rb_ary_uniq_bang(VALUE ary)
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);

View file

@ -1569,6 +1569,15 @@ class TestArray < Test::Unit::TestCase
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'))