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

ruby-changes:8491

From: mame <ko1@a...>
Date: Wed, 29 Oct 2008 23:31:06 +0900 (JST)
Subject: [ruby-changes:8491] Ruby:r20024 (trunk, ruby_1_9_1): * array.c (rb_ary_sort_bang): replacing array during sort broke

mame	2008-10-29 23:30:07 +0900 (Wed, 29 Oct 2008)

  New Revision: 20024

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

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

  Modified files:
    branches/ruby_1_9_1/ChangeLog
    branches/ruby_1_9_1/array.c
    trunk/ChangeLog
    trunk/array.c

Index: array.c
===================================================================
--- array.c	(revision 20023)
+++ array.c	(revision 20024)
@@ -1751,14 +1751,18 @@
 	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)) {
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 20023)
+++ ChangeLog	(revision 20024)
@@ -1,3 +1,8 @@
+Wed Oct 29 23:24:38 2008  Yusuke Endoh  <mame@t...>
+
+	* array.c (rb_ary_sort_bang): replacing array during sort broke
+	  invariant of array.
+
 Wed Oct 29 20:45:08 2008  Yusuke Endoh  <mame@t...>
 
 	* test/webrick/utils.rb (start_server): provide a reference to log of
Index: ruby_1_9_1/array.c
===================================================================
--- ruby_1_9_1/array.c	(revision 20023)
+++ ruby_1_9_1/array.c	(revision 20024)
@@ -1751,14 +1751,18 @@
 	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)) {
Index: ruby_1_9_1/ChangeLog
===================================================================
--- ruby_1_9_1/ChangeLog	(revision 20023)
+++ ruby_1_9_1/ChangeLog	(revision 20024)
@@ -1,3 +1,8 @@
+Wed Oct 29 23:24:38 2008  Yusuke Endoh  <mame@t...>
+
+	* array.c (rb_ary_sort_bang): replacing array during sort broke
+	  invariant of array.
+
 Wed Oct 29 20:45:08 2008  Yusuke Endoh  <mame@t...>
 
 	* test/webrick/utils.rb (start_server): provide a reference to log of

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

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