aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--array.c1
-rw-r--r--test/ruby/test_array.rb16
3 files changed, 22 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index d5aa621434..f13688ec18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+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
+ a callback method.
+
Wed Jun 12 12:00:15 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (FL_SET_EMBED): shared object is frozen even when get
diff --git a/array.c b/array.c
index 400403e22f..9bdbe78d5c 100644
--- a/array.c
+++ b/array.c
@@ -2321,6 +2321,7 @@ rb_ary_sort_bang(VALUE ary)
ruby_qsort(RARRAY_PTR(tmp), len, sizeof(VALUE),
rb_block_given_p()?sort_1:sort_2, &data);
+ rb_ary_modify(ary);
if (ARY_EMBED_P(tmp)) {
assert(ARY_EMBED_P(tmp));
if (ARY_SHARED_P(ary)) { /* ary might be destructively operated in the given block */
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 8a8af491c9..49628215b5 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -1378,6 +1378,22 @@ class TestArray < Test::Unit::TestCase
end
end
+ def test_sort_bang_with_freeze
+ ary = []
+ o1 = Object.new
+ o1.singleton_class.class_eval {
+ define_method(:<=>) {|v|
+ ary.freeze
+ 1
+ }
+ }
+ o2 = o1.dup
+ ary << o1 << o2
+ orig = ary.dup
+ assert_raise(RuntimeError, "frozen during comparison") {ary.sort!}
+ assert_equal(orig, ary, "must not be modified once frozen")
+ end
+
def test_to_a
a = @cls[ 1, 2, 3 ]
a_id = a.__id__