summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-17 05:01:52 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-17 05:01:52 +0000
commit9afd5465e216f4795bf952a072aae5b315a66d8d (patch)
tree974529fc2111b5434fba25710f098b18d1b9bbcd
parent02838f35084a801d0fa2cf5573ce6703d0075123 (diff)
* array.c (rb_ary_sort_bang): should not free shared pointer, and set
shared. [ruby-dev:34732] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--array.c3
-rw-r--r--test/ruby/test_array.rb10
3 files changed, 17 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 08d7f1f..8a41947 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat May 17 14:01:50 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * array.c (rb_ary_sort_bang): should not free shared pointer, and set
+ shared. [ruby-dev:34732]
+
Sat May 17 12:34:54 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* thread_pthread.c (Init_native_thread): Kernel#.sleep used never to
diff --git a/array.c b/array.c
index 635c7c7..6fd7a75 100644
--- a/array.c
+++ b/array.c
@@ -1514,10 +1514,11 @@ rb_ary_sort_bang(VALUE ary)
ruby_qsort(RARRAY_PTR(tmp), RARRAY_LEN(tmp), sizeof(VALUE),
rb_block_given_p()?sort_1:sort_2, &RBASIC(tmp)->klass);
if (RARRAY(ary)->ptr != RARRAY(tmp)->ptr) {
- xfree(RARRAY(ary)->ptr);
+ if (!ARY_SHARED_P(ary)) xfree(RARRAY(ary)->ptr);
RARRAY(ary)->ptr = RARRAY(tmp)->ptr;
RARRAY(ary)->len = RARRAY(tmp)->len;
RARRAY(ary)->aux.capa = RARRAY(tmp)->aux.capa;
+ FL_SET(ary, ELTS_SHARED);
};
FL_UNSET(ary, ELTS_SHARED);
RARRAY(tmp)->ptr = 0;
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index a5b4735..463701b 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -1152,6 +1152,16 @@ class TestArray < Test::Unit::TestCase
assert_match(/reentered/, e.message, '[ruby-core:16679]')
end
+ def test_sort_with_replace
+ xary = (1..100).to_a
+ 100.times do
+ ary = (1..100).to_a
+ ary.sort! {|a,b| ary.replace(xary); a <=> b}
+ GC.start
+ assert_equal(xary, ary, '[ruby-dev:34732]')
+ end
+ end
+
def test_to_a
a = @cls[ 1, 2, 3 ]
a_id = a.__id__