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

ruby-changes:54632

From: naruse <ko1@a...>
Date: Fri, 18 Jan 2019 06:43:11 +0900 (JST)
Subject: [ruby-changes:54632] naruse:r66847 (ruby_2_6): merge revision(s) 66756: [Backport #15479]

naruse	2019-01-18 06:39:14 +0900 (Fri, 18 Jan 2019)

  New Revision: 66847

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66847

  Log:
    merge revision(s) 66756: [Backport #15479]
    
    Mark array as "going to be modified" in `Array#reject!`
    
    Before this patch, if `reject!` is called on a shared array it can
    mutate the shared array rather than a copy.  This patch marks the array
    as "going to be modified" so that the shared source array isn't
    mutated.
    
    [Bug #15479] [ruby-core:90781]

  Modified directories:
    branches/ruby_2_6/
  Modified files:
    branches/ruby_2_6/array.c
    branches/ruby_2_6/test/ruby/test_array.rb
    branches/ruby_2_6/version.h
Index: ruby_2_6/array.c
===================================================================
--- ruby_2_6/array.c	(revision 66846)
+++ ruby_2_6/array.c	(revision 66847)
@@ -3540,6 +3540,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_6/array.c#L3540
 rb_ary_reject_bang(VALUE ary)
 {
     RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
+    rb_ary_modify(ary);
     return ary_reject_bang(ary);
 }
 
Index: ruby_2_6/version.h
===================================================================
--- ruby_2_6/version.h	(revision 66846)
+++ ruby_2_6/version.h	(revision 66847)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_6/version.h#L1
 #define RUBY_VERSION "2.6.0"
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 15
+#define RUBY_PATCHLEVEL 16
 
 #define RUBY_RELEASE_YEAR 2019
 #define RUBY_RELEASE_MONTH 1
Index: ruby_2_6/test/ruby/test_array.rb
===================================================================
--- ruby_2_6/test/ruby/test_array.rb	(revision 66846)
+++ ruby_2_6/test/ruby/test_array.rb	(revision 66847)
@@ -1308,6 +1308,65 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_6/test/ruby/test_array.rb#L1308
     assert_equal(@cls[7, 8, 9, 10], a, bug2545)
   end
 
+  def test_shared_array_reject!
+    c = []
+    b = [1, 2, 3, 4]
+    3.times do
+      a = b.dup
+      c << a.dup
+
+      begin
+        a.reject! do |x|
+          case x
+          when 2 then true
+          when 3 then raise StandardError, 'Oops'
+          else false
+          end
+        end
+      rescue StandardError
+      end
+
+      c << a.dup
+    end
+
+    bug90781 = '[ruby-core:90781]'
+    assert_equal [[1, 2, 3, 4],
+                  [1, 3, 4],
+                  [1, 2, 3, 4],
+                  [1, 3, 4],
+                  [1, 2, 3, 4],
+                  [1, 3, 4]], c, bug90781
+  end
+
+  def test_iseq_shared_array_reject!
+    c = []
+    3.times do
+      a = [1, 2, 3, 4]
+      c << a.dup
+
+      begin
+        a.reject! do |x|
+          case x
+          when 2 then true
+          when 3 then raise StandardError, 'Oops'
+          else false
+          end
+        end
+      rescue StandardError
+      end
+
+      c << a.dup
+    end
+
+    bug90781 = '[ruby-core:90781]'
+    assert_equal [[1, 2, 3, 4],
+                  [1, 3, 4],
+                  [1, 2, 3, 4],
+                  [1, 3, 4],
+                  [1, 2, 3, 4],
+                  [1, 3, 4]], c, bug90781
+  end
+
   def test_replace
     a = @cls[ 1, 2, 3]
     a_id = a.__id__
Index: ruby_2_6
===================================================================
--- ruby_2_6	(revision 66846)
+++ ruby_2_6	(revision 66847)

Property changes on: ruby_2_6
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r66756

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

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