ruby-changes:4952
From: ko1@a...
Date: Sat, 17 May 2008 14:02:13 +0900 (JST)
Subject: [ruby-changes:4952] nobu - Ruby:r16445 (trunk): * array.c (rb_ary_sort_bang): should not free shared pointer, and set
nobu 2008-05-17 14:01:52 +0900 (Sat, 17 May 2008) New Revision: 16445 Modified files: trunk/ChangeLog trunk/array.c trunk/test/ruby/test_array.rb Log: * array.c (rb_ary_sort_bang): should not free shared pointer, and set shared. [ruby-dev:34732] http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?r1=16445&r2=16444&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16445&r2=16444&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_array.rb?r1=16445&r2=16444&diff_format=u Index: array.c =================================================================== --- array.c (revision 16444) +++ array.c (revision 16445) @@ -1514,10 +1514,11 @@ 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; Index: ChangeLog =================================================================== --- ChangeLog (revision 16444) +++ ChangeLog (revision 16445) @@ -1,3 +1,8 @@ +Sat May 17 14:01:50 2008 Nobuyoshi Nakada <nobu@r...> + + * 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@y...> * thread_pthread.c (Init_native_thread): Kernel#.sleep used never to Index: test/ruby/test_array.rb =================================================================== --- test/ruby/test_array.rb (revision 16444) +++ test/ruby/test_array.rb (revision 16445) @@ -1152,6 +1152,16 @@ 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__ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/