зеркало из https://github.com/github/ruby.git
* 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:
Родитель
143f059bcd
Коммит
e2cb0b9766
|
@ -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>
|
||||
|
||||
* 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 {
|
||||
assert(!ARY_EMBED_P(tmp));
|
||||
if (ARY_EMBED_P(ary)) FL_UNSET_EMBED(ary);
|
||||
if (RARRAY_PTR(ary) != RARRAY_PTR(tmp)) {
|
||||
if (ARY_EMBED_P(ary) || RARRAY_PTR(ary) != RARRAY_PTR(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);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -1157,6 +1157,14 @@ class TestArray < Test::Unit::TestCase
|
|||
|
||||
assert_equal(@cls[1], @cls[1].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
|
||||
|
||||
def test_sort_with_callcc
|
||||
|
|
Загрузка…
Ссылка в новой задаче