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

ruby-changes:43705

From: nagachika <ko1@a...>
Date: Sat, 30 Jul 2016 12:21:56 +0900 (JST)
Subject: [ruby-changes:43705] nagachika:r55778 (ruby_2_3): merge revision(s) 54909, 55531: [Backport #12531]

nagachika	2016-07-30 12:21:51 +0900 (Sat, 30 Jul 2016)

  New Revision: 55778

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

  Log:
    merge revision(s) 54909,55531: [Backport #12531]
    
    proc.c: passed_block
    
    * proc.c (passed_block): extract conversion from passed proc value
      to rb_block_t pointer.
    * proc.c (passed_block): convert passed block symbol to proc.
      based on the patch by Daisuke Sato in [ruby-dev:49695].
      [Bug #12531]

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/ChangeLog
    branches/ruby_2_3/proc.c
    branches/ruby_2_3/test/ruby/test_symbol.rb
    branches/ruby_2_3/version.h
Index: ruby_2_3/test/ruby/test_symbol.rb
===================================================================
--- ruby_2_3/test/ruby/test_symbol.rb	(revision 55777)
+++ ruby_2_3/test/ruby/test_symbol.rb	(revision 55778)
@@ -229,6 +229,35 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_symbol.rb#L229
     assert_equal([false, false], m2.call(self, m2), "#{bug8531} nested without block")
   end
 
+  def test_block_curry_proc
+    assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
+    begin;
+    b = proc { true }.curry
+    assert(b.call, "without block")
+    assert(b.call { |o| o.to_s }, "with block")
+    assert(b.call(&:to_s), "with sym block")
+    end;
+  end
+
+  def test_block_curry_lambda
+    assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
+    begin;
+    b = lambda { true }.curry
+    assert(b.call, "without block")
+    assert(b.call { |o| o.to_s }, "with block")
+    assert(b.call(&:to_s), "with sym block")
+    end;
+  end
+
+  def test_block_method_to_proc
+    assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
+    begin;
+    b = method(:tap).to_proc
+    assert(b.call { |o| o.to_s }, "with block")
+    assert(b.call(&:to_s), "with sym block")
+    end;
+  end
+
   def test_succ
     assert_equal(:fop, :foo.succ)
   end
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 55777)
+++ ruby_2_3/version.h	(revision 55778)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.2"
 #define RUBY_RELEASE_DATE "2016-07-30"
-#define RUBY_PATCHLEVEL 140
+#define RUBY_PATCHLEVEL 141
 
 #define RUBY_RELEASE_YEAR 2016
 #define RUBY_RELEASE_MONTH 7
Index: ruby_2_3/proc.c
===================================================================
--- ruby_2_3/proc.c	(revision 55777)
+++ ruby_2_3/proc.c	(revision 55778)
@@ -809,6 +809,20 @@ check_argc(long argc) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/proc.c#L809
 #define check_argc(argc) (argc)
 #endif
 
+static rb_block_t *
+passed_block(VALUE pass_procval)
+{
+    if (!NIL_P(pass_procval)) {
+	rb_proc_t *pass_proc;
+	if (SYMBOL_P(pass_procval)) {
+	    pass_procval = sym_proc_new(rb_cProc, pass_procval);
+	}
+	GetProcPtr(pass_procval, pass_proc);
+	return &pass_proc->block;
+    }
+    return 0;
+}
+
 VALUE
 rb_proc_call(VALUE self, VALUE args)
 {
@@ -829,12 +843,7 @@ rb_proc_call_with_block(VALUE self, int https://github.com/ruby/ruby/blob/trunk/ruby_2_3/proc.c#L843
     rb_block_t *block = 0;
     GetProcPtr(self, proc);
 
-    if (!NIL_P(pass_procval)) {
-	rb_proc_t *pass_proc;
-	GetProcPtr(pass_procval, pass_proc);
-	block = &pass_proc->block;
-    }
-
+    block = passed_block(pass_procval);
     vret = rb_vm_invoke_proc(GET_THREAD(), proc, argc, argv, block);
     RB_GC_GUARD(self);
     RB_GC_GUARD(pass_procval);
@@ -1981,15 +1990,8 @@ rb_method_call_with_block(int argc, cons https://github.com/ruby/ruby/blob/trunk/ruby_2_3/proc.c#L1990
     }
     if ((state = EXEC_TAG()) == 0) {
 	rb_thread_t *th = GET_THREAD();
-	rb_block_t *block = 0;
-
-	if (!NIL_P(pass_procval)) {
-	    rb_proc_t *pass_proc;
-	    GetProcPtr(pass_procval, pass_proc);
-	    block = &pass_proc->block;
-	}
 
-	th->passed_block = block;
+	th->passed_block = passed_block(pass_procval);
 	VAR_INITIALIZED(data);
 	result = rb_vm_call(th, data->recv, data->me->called_id, argc, argv, method_callable_method_entry(data));
     }
Index: ruby_2_3/ChangeLog
===================================================================
--- ruby_2_3/ChangeLog	(revision 55777)
+++ ruby_2_3/ChangeLog	(revision 55778)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1
+Sat Jul 30 12:10:51 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* proc.c (passed_block): convert passed block symbol to proc.
+	  based on the patch by Daisuke Sato in [ruby-dev:49695].
+	  [Bug #12531]
+
 Sat Jul 30 10:58:49 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_insnhelper.c (vm_throw_start): check if the iseq is symbol

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r54909,55531


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

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