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

ruby-changes:27076

From: nobu <ko1@a...>
Date: Thu, 7 Feb 2013 15:33:32 +0900 (JST)
Subject: [ruby-changes:27076] nobu:r39128 (trunk): mkmf.rb: fix merge_libs

nobu	2013-02-07 15:33:22 +0900 (Thu, 07 Feb 2013)

  New Revision: 39128

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

  Log:
    mkmf.rb: fix merge_libs
    
    * lib/mkmf.rb (MakeMakefile#merge_libs): insert following reversal
      ordered elements just after the duplicated element, not overwriting
      successive elements.  [ruby-core:50314] [Bug #7467]

  Modified files:
    trunk/ChangeLog
    trunk/lib/mkmf.rb
    trunk/test/mkmf/test_libs.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39127)
+++ ChangeLog	(revision 39128)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Feb  7 15:33:17 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/mkmf.rb (MakeMakefile#merge_libs): insert following reversal
+	  ordered elements just after the duplicated element, not overwriting
+	  successive elements.  [ruby-core:50314] [Bug #7467]
+
 Thu Feb  7 14:56:15 2013  Eric Hodel  <drbrain@s...>
 
 	* lib/rubygems/package.rb:  Ensure digests are generated for signing.
Index: lib/mkmf.rb
===================================================================
--- lib/mkmf.rb	(revision 39127)
+++ lib/mkmf.rb	(revision 39128)
@@ -269,17 +269,15 @@ module MakeMakefile https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L269
 
   def merge_libs(*libs)
     libs.inject([]) do |x, y|
-      xy = x & y
-      xn = yn = 0
       y = y.inject([]) {|ary, e| ary.last == e ? ary : ary << e}
       y.each_with_index do |v, yi|
-        if xy.include?(v)
-          xi = [x.index(v), xn].max()
-          x[xi, 1] = y[yn..yi]
-          xn, yn = xi + (yi - yn + 1), yi + 1
+        if xi = x.rindex(v)
+          x[(xi+1)..-1] = merge_libs(y[(yi+1)..-1], x[(xi+1)..-1])
+          x[xi, 0] = y[0...yi]
+          break
         end
-      end
-      x.concat(y[yn..-1] || [])
+      end and x.concat(y)
+      x
     end
   end
 
Index: test/mkmf/test_libs.rb
===================================================================
--- test/mkmf/test_libs.rb	(revision 39127)
+++ test/mkmf/test_libs.rb	(revision 39128)
@@ -65,5 +65,22 @@ class TestMkmf https://github.com/ruby/ruby/blob/trunk/test/mkmf/test_libs.rb#L65
       assert_in_order(array, "c", "d" , bug)
       ## assume that a and c have no dependency
     end
+
+    def test_merge_reversal_followed
+      bug7467 = '[ruby-core:50314] [Bug #7467]'
+      array = nil
+      assert_nothing_raised(bug7467) {
+        array = merge_libs(%w[a b c d e f g h], %w[d c d e], [])
+      }
+      assert_in_order(array, "a", "b", bug7467)
+      assert_in_order(array, "b", "c", bug7467)
+      assert_in_order(array, "c", "d", bug7467)
+      assert_in_order(array, "d", "e", bug7467)
+      assert_in_order(array, "e", "f", bug7467)
+      assert_in_order(array, "f", "g", bug7467)
+      assert_in_order(array, "g", "h", bug7467)
+      assert_in_order(array, "d", "c", bug7467)
+      assert_in_order(array, "c", "e", bug7467)
+    end
   end
 end if RUBY_ENGINE == "ruby"

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

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