[前][次][番号順一覧][スレッド一覧]

ruby-changes:8514

From: mame <ko1@a...>
Date: Thu, 30 Oct 2008 02:25:11 +0900 (JST)
Subject: [ruby-changes:8514] Ruby:r20048 (trunk, ruby_1_9_1): * array.c (rb_ary_sort_bang): remove SEGV when replacing array with

mame	2008-10-30 02:24:44 +0900 (Thu, 30 Oct 2008)

  New Revision: 20048

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20048

  Log:
    * 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.

  Modified files:
    branches/ruby_1_9_1/ChangeLog
    branches/ruby_1_9_1/array.c
    branches/ruby_1_9_1/test/ruby/test_array.rb
    trunk/ChangeLog
    trunk/array.c
    trunk/test/ruby/test_array.rb

Index: array.c
===================================================================
--- array.c	(revision 20047)
+++ array.c	(revision 20048)
@@ -1758,10 +1758,12 @@
         }
         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 {
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 20047)
+++ ChangeLog	(revision 20048)
@@ -1,3 +1,10 @@
+Thu Oct 30 02:20:33 2008  Yusuke Endoh  <mame@t...>
+
+	* 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@t...>
 
 	* test/ruby/test_array.rb: add some tests.
Index: test/ruby/test_array.rb
===================================================================
--- test/ruby/test_array.rb	(revision 20047)
+++ test/ruby/test_array.rb	(revision 20048)
@@ -1157,6 +1157,14 @@
 
     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
Index: ruby_1_9_1/array.c
===================================================================
--- ruby_1_9_1/array.c	(revision 20047)
+++ ruby_1_9_1/array.c	(revision 20048)
@@ -1758,10 +1758,12 @@
         }
         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 {
Index: ruby_1_9_1/ChangeLog
===================================================================
--- ruby_1_9_1/ChangeLog	(revision 20047)
+++ ruby_1_9_1/ChangeLog	(revision 20048)
@@ -1,3 +1,10 @@
+Thu Oct 30 02:20:33 2008  Yusuke Endoh  <mame@t...>
+
+	* 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@t...>
 
 	* test/ruby/test_array.rb: add some tests.
Index: ruby_1_9_1/test/ruby/test_array.rb
===================================================================
--- ruby_1_9_1/test/ruby/test_array.rb	(revision 20047)
+++ ruby_1_9_1/test/ruby/test_array.rb	(revision 20048)
@@ -1157,6 +1157,14 @@
 
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]