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

ruby-changes:33522

From: nobu <ko1@a...>
Date: Wed, 16 Apr 2014 23:47:45 +0900 (JST)
Subject: [ruby-changes:33522] nobu:r45603 (trunk): enum.c: fix condition to recycle block argument

nobu	2014-04-16 23:47:38 +0900 (Wed, 16 Apr 2014)

  New Revision: 45603

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

  Log:
    enum.c: fix condition to recycle block argument
    
    * enum.c (dont_recycle_block_arg): fix condition to recycle block
      argument.  lambda with rest can get internal array directly.
      [ruby-core:62060] [Bug #9749]

  Modified files:
    trunk/ChangeLog
    trunk/enum.c
    trunk/test/ruby/test_enum.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45602)
+++ ChangeLog	(revision 45603)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Apr 16 23:47:36 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* enum.c (dont_recycle_block_arg): fix condition to recycle block
+	  argument.  lambda with rest can get internal array directly.
+	  [ruby-core:62060] [Bug #9749]
+
 Wed Apr 16 09:51:16 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/openssl/ossl_pkey.c (ossl_pkey_verify): as EVP_VerifyFinal()
Index: enum.c
===================================================================
--- enum.c	(revision 45602)
+++ enum.c	(revision 45603)
@@ -2058,7 +2058,7 @@ enum_each_entry(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/enum.c#L2058
     return obj;
 }
 
-#define dont_recycle_block_arg(arity) ((arity) == 1 || (arity) == -1)
+#define dont_recycle_block_arg(arity) ((arity) == 1 || (arity) < 0)
 #define nd_no_recycle u2.value
 
 static VALUE
Index: test/ruby/test_enum.rb
===================================================================
--- test/ruby/test_enum.rb	(revision 45602)
+++ test/ruby/test_enum.rb	(revision 45603)
@@ -342,12 +342,22 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L342
     ary = []
     (1..10).each_slice(3) {|a| ary << a}
     assert_equal([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]], ary)
+
+    bug9749 = '[ruby-core:62060] [Bug #9749]'
+    ary.clear
+    (1..10).each_slice(3, &lambda {|a, *| ary << a})
+    assert_equal([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]], ary, bug9749)
   end
 
   def test_each_cons
     ary = []
     (1..5).each_cons(3) {|a| ary << a}
     assert_equal([[1, 2, 3], [2, 3, 4], [3, 4, 5]], ary)
+
+    bug9749 = '[ruby-core:62060] [Bug #9749]'
+    ary.clear
+    (1..5).each_cons(3, &lambda {|a, *| ary << a})
+    assert_equal([[1, 2, 3], [2, 3, 4], [3, 4, 5]], ary, bug9749)
   end
 
   def test_zip

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

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