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

ruby-changes:41095

From: shugo <ko1@a...>
Date: Thu, 17 Dec 2015 16:16:20 +0900 (JST)
Subject: [ruby-changes:41095] shugo:r53170 (trunk): * proc.c (rb_block_arity): should not call GetProcPtr() for symbols.

shugo	2015-12-17 16:16:14 +0900 (Thu, 17 Dec 2015)

  New Revision: 53170

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

  Log:
    * proc.c (rb_block_arity): should not call GetProcPtr() for symbols.
      [ruby-core:72205] [Bug #11830]

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/test/ruby/test_symbol.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53169)
+++ ChangeLog	(revision 53170)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Dec 17 16:13:10 2015  Shugo Maeda  <shugo@r...>
+
+	* proc.c (rb_block_arity): should not call GetProcPtr() for symbols.
+	  [ruby-core:72205] [Bug #11830]
+
 Thu Dec 17 14:16:29 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* string.c (rb_str_scrub): the result should be infected by the
Index: proc.c
===================================================================
--- proc.c	(revision 53169)
+++ proc.c	(revision 53170)
@@ -956,10 +956,15 @@ rb_block_arity(void) https://github.com/ruby/ruby/blob/trunk/proc.c#L956
     min = rb_block_min_max_arity(block, &max);
     proc_value = block->proc;
     if (proc_value) {
-	rb_proc_t *proc;
-	GetProcPtr(proc_value, proc);
-	if (proc)
-	    return (proc->is_lambda ? min == max : max != UNLIMITED_ARGUMENTS) ? min : -min-1;
+	if (SYMBOL_P(proc_value)) {
+	    return -1;
+	}
+	else {
+	    rb_proc_t *proc;
+	    GetProcPtr(proc_value, proc);
+	    if (proc)
+		return (proc->is_lambda ? min == max : max != UNLIMITED_ARGUMENTS) ? min : -min-1;
+	}
     }
     return max != UNLIMITED_ARGUMENTS ? min : -min-1;
 }
Index: test/ruby/test_symbol.rb
===================================================================
--- test/ruby/test_symbol.rb	(revision 53169)
+++ test/ruby/test_symbol.rb	(revision 53170)
@@ -157,6 +157,13 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L157
     assert_equal(1, first, bug11594)
   end
 
+  def test_to_proc_for_hash_each
+    bug11830 = '[ruby-core:72205] [Bug #11830]'
+    assert_normal_exit(<<-'end;', bug11830) # do
+      {}.each(&:destroy)
+    end;
+  end
+
   def test_call
     o = Object.new
     def o.foo(x, y); x + y; end

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

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