* array.c (rb_ary_sort_bang): replacing array during sort broke

invariant of array.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2008-10-29 14:30:07 +00:00
Родитель 224471fd57
Коммит 7451e34428
2 изменённых файлов: 11 добавлений и 2 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Wed Oct 29 23:24:38 2008 Yusuke Endoh <mame@tsg.ne.jp>
* array.c (rb_ary_sort_bang): replacing array during sort broke
invariant of array.
Wed Oct 29 20:45:08 2008 Yusuke Endoh <mame@tsg.ne.jp>
* test/webrick/utils.rb (start_server): provide a reference to log of

Просмотреть файл

@ -1751,14 +1751,18 @@ rb_ary_sort_bang(VALUE ary)
ruby_qsort(RARRAY_PTR(tmp), RARRAY_LEN(tmp), sizeof(VALUE),
rb_block_given_p()?sort_1:sort_2, &data);
if (ARY_EMBED_P(ary) || ARY_EMBED_P(tmp)) {
if (ARY_EMBED_P(tmp)) {
assert(ARY_EMBED_P(tmp));
if (ARY_SHARED_P(ary)) { /* ary might be destructively operated in the given block */
rb_ary_unshared(ary);
FL_SET_EMBED(ary);
}
MEMCPY(RARRAY_PTR(ary), ARY_EMBED_PTR(tmp), VALUE, ARY_EMBED_LEN(tmp));
ARY_SET_LEN(ary, ARY_EMBED_LEN(tmp));
}
else {
assert(!ARY_EMBED_P(ary));
assert(!ARY_EMBED_P(tmp));
if (ARY_EMBED_P(ary)) FL_UNSET_EMBED(ary);
if (RARRAY_PTR(ary) != RARRAY_PTR(tmp)) {
assert(!ARY_SHARED_P(tmp));
if (ARY_SHARED_P(ary)) {