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

ruby-changes:39975

From: nobu <ko1@a...>
Date: Tue, 6 Oct 2015 15:38:19 +0900 (JST)
Subject: [ruby-changes:39975] nobu:r52056 (trunk): vm_args.c: wrap symbol ifunc

nobu	2015-10-06 15:38:08 +0900 (Tue, 06 Oct 2015)

  New Revision: 52056

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

  Log:
    vm_args.c: wrap symbol ifunc
    
    * vm_args.c (args_setup_block_parameter): wrap a symbol in ifunc
      by a proc as a block parameter.

  Modified files:
    trunk/internal.h
    trunk/string.c
    trunk/test/ruby/test_symbol.rb
    trunk/vm_args.c
Index: string.c
===================================================================
--- string.c	(revision 52055)
+++ string.c	(revision 52056)
@@ -8946,6 +8946,7 @@ rb_sym_proc_call(VALUE args, VALUE sym, https://github.com/ruby/ruby/blob/trunk/string.c#L8946
     return rb_funcall_with_block(obj, (ID)sym, argc - 1, argv + 1, passed_proc);
 }
 
+#define sym_to_proc rb_sym_to_proc
 /*
  * call-seq:
  *   sym.to_proc
@@ -8955,7 +8956,7 @@ rb_sym_proc_call(VALUE args, VALUE sym, https://github.com/ruby/ruby/blob/trunk/string.c#L8956
  *   (1..3).collect(&:to_s)  #=> ["1", "2", "3"]
  */
 
-static VALUE
+VALUE
 sym_to_proc(VALUE sym)
 {
     static VALUE sym_proc_cache = Qfalse;
Index: internal.h
===================================================================
--- internal.h	(revision 52055)
+++ internal.h	(revision 52056)
@@ -1110,6 +1110,7 @@ VALUE rb_external_str_with_enc(VALUE str https://github.com/ruby/ruby/blob/trunk/internal.h#L1110
 #define is_broken_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN)
 size_t rb_str_memsize(VALUE);
 VALUE rb_sym_proc_call(VALUE args, VALUE sym, int argc, const VALUE *argv, VALUE passed_proc);
+VALUE rb_sym_to_proc(VALUE sym);
 
 /* struct.c */
 VALUE rb_struct_init_copy(VALUE copy, VALUE s);
Index: test/ruby/test_symbol.rb
===================================================================
--- test/ruby/test_symbol.rb	(revision 52055)
+++ test/ruby/test_symbol.rb	(revision 52056)
@@ -140,6 +140,13 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L140
     end;
   end
 
+  def test_to_proc_arg
+    assert_separately([], <<-"end;", timeout: 5.0)
+      def (obj = Object.new).proc(&b) b; end
+      assert_same(:itself.to_proc, obj.proc(&:itself))
+    end;
+  end
+
   def test_call
     o = Object.new
     def o.foo(x, y); x + y; end
Index: vm_args.c
===================================================================
--- vm_args.c	(revision 52055)
+++ vm_args.c	(revision 52056)
@@ -478,6 +478,10 @@ args_setup_block_parameter(rb_thread_t * https://github.com/ruby/ruby/blob/trunk/vm_args.c#L478
 	    GetProcPtr(blockval, proc);
 	    calling->blockptr = &proc->block;
 	}
+	else if (RUBY_VM_IFUNC_P(blockptr->proc)) {
+	    const ID mid = (ID)((struct vm_ifunc *)blockptr->proc)->data;
+	    blockval = rb_sym_to_proc(ID2SYM(mid));
+	}
 	else {
 	    blockval = blockptr->proc;
 	}

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

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