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

ruby-changes:31412

From: usa <ko1@a...>
Date: Fri, 1 Nov 2013 00:00:14 +0900 (JST)
Subject: [ruby-changes:31412] usa:r43491 (ruby_1_9_3): merge revision(s) 42040, 42041, 42047, 42068, 42069: [Backport #8654]

usa	2013-11-01 00:00:06 +0900 (Fri, 01 Nov 2013)

  New Revision: 43491

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

  Log:
    merge revision(s) 42040,42041,42047,42068,42069: [Backport #8654]
    
    * array.c (rb_ary_count): iterate items appropriately.
      [Bug #8654]
    
    * array.c (rb_ary_count): check length to avoid SEGV
      while iterating. Remove other pointer loop when arg is given.
    
    * test/ruby/test_array.rb (test_count): add test for bug.
      [ruby-core:56072] [Bug #8654]
    
    * test/ruby/test_array.rb (test_count): add a test case for #count
      with an argument. See Bug #8654.

  Modified directories:
    branches/ruby_1_9_3/
  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/array.c
    branches/ruby_1_9_3/test/ruby/test_array.rb
    branches/ruby_1_9_3/version.h
Index: ruby_1_9_3/array.c
===================================================================
--- ruby_1_9_3/array.c	(revision 43490)
+++ ruby_1_9_3/array.c	(revision 43491)
@@ -3692,27 +3692,28 @@ rb_ary_compact(VALUE ary) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/array.c#L3692
 static VALUE
 rb_ary_count(int argc, VALUE *argv, VALUE ary)
 {
-    long n = 0;
+    long i, n = 0;
 
     if (argc == 0) {
-	VALUE *p, *pend;
+	VALUE v;
 
 	if (!rb_block_given_p())
 	    return LONG2NUM(RARRAY_LEN(ary));
 
-	for (p = RARRAY_PTR(ary), pend = p + RARRAY_LEN(ary); p < pend; p++) {
-	    if (RTEST(rb_yield(*p))) n++;
+	for (i = 0; i < RARRAY_LEN(ary); i++) {
+	    v = RARRAY_PTR(ary)[i];
+	    if (RTEST(rb_yield(v))) n++;
 	}
     }
     else {
-	VALUE obj, *p, *pend;
+	VALUE obj;
 
 	rb_scan_args(argc, argv, "1", &obj);
 	if (rb_block_given_p()) {
 	    rb_warn("given block not used");
 	}
-	for (p = RARRAY_PTR(ary), pend = p + RARRAY_LEN(ary); p < pend; p++) {
-	    if (rb_equal(*p, obj)) n++;
+	for (i = 0; i < RARRAY_LEN(ary); i++) {
+	    if (rb_equal(RARRAY_PTR(ary)[i], obj)) n++;
 	}
     }
 
Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 43490)
+++ ruby_1_9_3/ChangeLog	(revision 43491)
@@ -1,3 +1,21 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ChangeLog#L1
+Thu Oct 31 23:57:22 2013  Benoit Daloze  <eregontp@g...>
+
+	* test/ruby/test_array.rb (test_count): add a test case for #count
+	  with an argument. See Bug #8654.
+
+Thu Oct 31 23:57:22 2013  Benoit Daloze  <eregontp@g...>
+
+	* array.c (rb_ary_count): check length to avoid SEGV
+	  while iterating. Remove other pointer loop when arg is given.
+
+	* test/ruby/test_array.rb (test_count): add test for bug.
+	  [ruby-core:56072] [Bug #8654]
+
+Thu Oct 31 23:57:22 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* array.c (rb_ary_count): iterate items appropriately.
+	  [Bug #8654]
+
 Thu Oct 31 23:42:39 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/tempfile.rb (Tempfile#unlink): finalizer is no longer needed
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 43490)
+++ ruby_1_9_3/version.h	(revision 43491)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/version.h#L1
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 479
+#define RUBY_PATCHLEVEL 480
 
 #define RUBY_RELEASE_DATE "2013-10-31"
 #define RUBY_RELEASE_YEAR 2013
Index: ruby_1_9_3/test/ruby/test_array.rb
===================================================================
--- ruby_1_9_3/test/ruby/test_array.rb	(revision 43490)
+++ ruby_1_9_3/test/ruby/test_array.rb	(revision 43491)
@@ -552,6 +552,29 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/test/ruby/test_array.rb#L552
     assert_equal(3, a.count {|x| x % 2 == 1 })
     assert_equal(2, a.count(1) {|x| x % 2 == 1 })
     assert_raise(ArgumentError) { a.count(0, 1) }
+
+    bug8654 = '[ruby-core:56072]'
+    assert_in_out_err [], <<-EOS, ["0"], [], bug8654
+      a1 = []
+      a2 = Array.new(100) { |i| i }
+      a2.count do |i|
+        p i
+        a2.replace(a1) if i == 0
+      end
+    EOS
+
+    assert_in_out_err [], <<-EOS, ["[]", "0"], [], bug8654
+      ARY = Array.new(100) { |i| i }
+      class Fixnum
+        alias old_equal ==
+        def == other
+          ARY.replace([]) if self.equal?(0)
+          p ARY
+          self.equal?(other)
+        end
+      end
+      p ARY.count(42)
+    EOS
   end
 
   def test_delete
@@ -1624,8 +1647,8 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/test/ruby/test_array.rb#L1647
                       [2,2,2,2],[2,2,2,3],[2,2,3,3],[2,3,3,3],[3,3,3,3]],
                  a.repeated_combination(4).to_a.sort)
     assert_equal(@cls[], a.repeated_combination(-1).to_a)
-    assert_equal("abcde".each_char.to_a.repeated_combination(5).map{|a|a.sort}.sort,
-                 "edcba".each_char.to_a.repeated_combination(5).map{|a|a.sort}.sort)
+    assert_equal("abcde".each_char.to_a.repeated_combination(5).map{|e|e.sort}.sort,
+                 "edcba".each_char.to_a.repeated_combination(5).map{|e|e.sort}.sort)
     assert_equal(@cls[].repeated_combination(0).to_a, @cls[[]])
     assert_equal(@cls[].repeated_combination(1).to_a, @cls[])
 

Property changes on: ruby_1_9_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r42040-42041,42047,42068-42069


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

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