mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c (rb_ary_sort_bang): remove SEGV when replacing array with
embedded one during sort. * test/ruby/test_array.rb (test_sort!): add tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20048 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
143f059bcd
commit
e2cb0b9766
3 changed files with 20 additions and 3 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Thu Oct 30 02:20:33 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
|
* array.c (rb_ary_sort_bang): remove SEGV when replacing array with
|
||||||
|
embedded one during sort.
|
||||||
|
|
||||||
|
* test/ruby/test_array.rb (test_sort!): add tests for above.
|
||||||
|
|
||||||
Thu Oct 30 01:44:23 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
Thu Oct 30 01:44:23 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
* test/ruby/test_array.rb: add some tests.
|
* test/ruby/test_array.rb: add some tests.
|
||||||
|
|
8
array.c
8
array.c
|
@ -1758,10 +1758,12 @@ rb_ary_sort_bang(VALUE ary)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(!ARY_EMBED_P(tmp));
|
assert(!ARY_EMBED_P(tmp));
|
||||||
if (ARY_EMBED_P(ary)) FL_UNSET_EMBED(ary);
|
if (ARY_EMBED_P(ary) || RARRAY_PTR(ary) != RARRAY_PTR(tmp)) {
|
||||||
if (RARRAY_PTR(ary) != RARRAY_PTR(tmp)) {
|
|
||||||
assert(!ARY_SHARED_P(tmp));
|
assert(!ARY_SHARED_P(tmp));
|
||||||
if (ARY_SHARED_P(ary)) {
|
if (ARY_EMBED_P(ary)) {
|
||||||
|
FL_UNSET_EMBED(ary);
|
||||||
|
}
|
||||||
|
else if (ARY_SHARED_P(ary)) {
|
||||||
rb_ary_unshare(ary);
|
rb_ary_unshare(ary);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1157,6 +1157,14 @@ class TestArray < Test::Unit::TestCase
|
||||||
|
|
||||||
assert_equal(@cls[1], @cls[1].sort!)
|
assert_equal(@cls[1], @cls[1].sort!)
|
||||||
assert_equal(@cls[], @cls[].sort!)
|
assert_equal(@cls[], @cls[].sort!)
|
||||||
|
|
||||||
|
a = @cls[4, 3, 2, 1]
|
||||||
|
a.sort! {|m, n| a.replace([9, 8, 7, 6]); m <=> n }
|
||||||
|
assert_equal([1, 2, 3, 4], a)
|
||||||
|
|
||||||
|
a = @cls[4, 3, 2, 1]
|
||||||
|
a.sort! {|m, n| a.replace([9, 8, 7]); m <=> n }
|
||||||
|
assert_equal([1, 2, 3, 4], a)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_with_callcc
|
def test_sort_with_callcc
|
||||||
|
|
Loading…
Add table
Reference in a new issue