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

ruby-changes:50664

From: usa <ko1@a...>
Date: Mon, 19 Mar 2018 00:33:41 +0900 (JST)
Subject: [ruby-changes:50664] usa:r62827 (ruby_2_3): merge revision(s) 60666, 60667, 60668: [Backport #14082]

usa	2018-03-19 00:33:37 +0900 (Mon, 19 Mar 2018)

  New Revision: 62827

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

  Log:
    merge revision(s) 60666,60667,60668: [Backport #14082]
    
    Fix size on Enumerable#cycle when the size is 0 [Bug #14082].
    
    Patch by Kenichi Kamiya
    
    test/ruby/test_lazy_enumerator.rb: test for [Bug #14082]
    
    enum.c: check argument first
    
    * enum.c (enum_cycle_size): check an argument before the size of
      the receiver, if it is given.

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/ChangeLog
    branches/ruby_2_3/enum.c
    branches/ruby_2_3/test/ruby/test_enumerator.rb
    branches/ruby_2_3/test/ruby/test_lazy_enumerator.rb
    branches/ruby_2_3/version.h
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 62826)
+++ ruby_2_3/version.h	(revision 62827)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.7"
 #define RUBY_RELEASE_DATE "2018-03-19"
-#define RUBY_PATCHLEVEL 427
+#define RUBY_PATCHLEVEL 428
 
 #define RUBY_RELEASE_YEAR 2018
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_3/test/ruby/test_lazy_enumerator.rb
===================================================================
--- ruby_2_3/test/ruby/test_lazy_enumerator.rb	(revision 62826)
+++ ruby_2_3/test/ruby/test_lazy_enumerator.rb	(revision 62827)
@@ -480,6 +480,15 @@ EOS https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_lazy_enumerator.rb#L480
     assert_equal Float::INFINITY, loop.lazy.cycle.size
     assert_equal nil, lazy.select{}.cycle(4).size
     assert_equal nil, lazy.select{}.cycle.size
+
+    class << (obj = Object.new)
+      def each; end
+      def size; 0; end
+      include Enumerable
+    end
+    lazy = obj.lazy
+    assert_equal 0, lazy.cycle.size
+    assert_raise(TypeError) {lazy.cycle("").size}
   end
 
   def test_map_zip
Index: ruby_2_3/test/ruby/test_enumerator.rb
===================================================================
--- ruby_2_3/test/ruby/test_enumerator.rb	(revision 62826)
+++ ruby_2_3/test/ruby/test_enumerator.rb	(revision 62827)
@@ -575,13 +575,22 @@ class TestEnumerator < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_enumerator.rb#L575
     assert_equal Float::INFINITY, [:foo].cycle.size
     assert_equal 10, [:foo, :bar].cycle(5).size
     assert_equal 0,  [:foo, :bar].cycle(-10).size
+    assert_equal Float::INFINITY, {foo: 1}.cycle.size
+    assert_equal 10, {foo: 1, bar: 2}.cycle(5).size
+    assert_equal 0,  {foo: 1, bar: 2}.cycle(-10).size
     assert_equal 0,  [].cycle.size
     assert_equal 0,  [].cycle(5).size
+    assert_equal 0,  {}.cycle.size
+    assert_equal 0,  {}.cycle(5).size
 
     assert_equal nil, @obj.cycle.size
     assert_equal nil, @obj.cycle(5).size
     assert_equal Float::INFINITY, @sized.cycle.size
     assert_equal 126, @sized.cycle(3).size
+    assert_equal Float::INFINITY, [].to_enum { 42 }.cycle.size
+    assert_equal 0, [].to_enum { 0 }.cycle.size
+
+    assert_raise(TypeError) {[].to_enum { 0 }.cycle("").size}
   end
 
   def test_size_for_loops
Index: ruby_2_3/ChangeLog
===================================================================
--- ruby_2_3/ChangeLog	(revision 62826)
+++ ruby_2_3/ChangeLog	(revision 62827)
@@ -1,3 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1
+Mon Mar 19 00:32:31 2018  Nobuyoshi Nakada  <nobu@r...>
+
+	* test/ruby/test_lazy_enumerator.rb: test for [Bug #14082]
+
+	enum.c: check argument first
+
+	* enum.c (enum_cycle_size): check an argument before the size of the
+	  receiver, if it is given.
+
+Mon Mar 19 00:32:31 2018  Marc-Andre Lafortune  <ruby-core@m...>
+
+	Fix size on Enumerable#cycle when the size is 0 [Bug #14082].
+
+	Patch by Kenichi Kamiya
+
 Mon Mar 19 00:28:28 2018  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (parser_here_document): an escaped newline is not an
Index: ruby_2_3/enum.c
===================================================================
--- ruby_2_3/enum.c	(revision 62826)
+++ ruby_2_3/enum.c	(revision 62827)
@@ -2678,17 +2678,19 @@ cycle_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, ar https://github.com/ruby/ruby/blob/trunk/ruby_2_3/enum.c#L2678
 static VALUE
 enum_cycle_size(VALUE self, VALUE args, VALUE eobj)
 {
-    long mul;
+    long mul = 0;
     VALUE n = Qnil;
-    VALUE size = enum_size(self, args, 0);
-
-    if (size == Qnil) return Qnil;
+    VALUE size;
 
     if (args && (RARRAY_LEN(args) > 0)) {
 	n = RARRAY_AREF(args, 0);
+	if (!NIL_P(n)) mul = NUM2LONG(n);
     }
-    if (n == Qnil) return DBL2NUM(INFINITY);
-    mul = NUM2LONG(n);
+
+    size = enum_size(self, args, 0);
+    if (NIL_P(size) || size == INT2FIX(0)) return size;
+
+    if (NIL_P(n)) return DBL2NUM(INFINITY);
     if (mul <= 0) return INT2FIX(0);
     return rb_funcall(size, '*', 1, LONG2FIX(mul));
 }
Index: ruby_2_3
===================================================================
--- ruby_2_3	(revision 62826)
+++ ruby_2_3	(revision 62827)

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r60666-60668

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

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