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

ruby-changes:31833

From: nobu <ko1@a...>
Date: Fri, 29 Nov 2013 17:06:25 +0900 (JST)
Subject: [ruby-changes:31833] nobu:r43912 (trunk): vm_eval.c: rb_yield_block

nobu	2013-11-29 17:06:19 +0900 (Fri, 29 Nov 2013)

  New Revision: 43912

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

  Log:
    vm_eval.c: rb_yield_block
    
    * vm_eval.c (rb_yield_block): yield block with rb_block_call_func
      arguments.
    * range.c (range_each): use rb_yield_block.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/ruby.h
    trunk/range.c
    trunk/vm.c
    trunk/vm_eval.c
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 43911)
+++ include/ruby/ruby.h	(revision 43912)
@@ -1509,6 +1509,7 @@ VALUE rb_yield(VALUE); https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1509
 VALUE rb_yield_values(int n, ...);
 VALUE rb_yield_values2(int n, const VALUE *argv);
 VALUE rb_yield_splat(VALUE);
+VALUE rb_yield_block(VALUE, VALUE, int, const VALUE *, VALUE); /* rb_block_call_func */
 int rb_block_given_p(void);
 void rb_need_block(void);
 VALUE rb_iterate(VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43911)
+++ ChangeLog	(revision 43912)
@@ -1,4 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Fri Nov 29 17:02:48 2013  Nobuyoshi Nakada  <nobu@r...>
+Fri Nov 29 17:06:09 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_eval.c (rb_yield_block): yield block with rb_block_call_func
+	  arguments.
+
+	* range.c (range_each): use rb_yield_block.
 
 	* include/ruby/ruby.h (RB_BLOCK_CALL_FUNC_ARGLIST): constify argv.
 
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 43911)
+++ vm_eval.c	(revision 43912)
@@ -14,6 +14,7 @@ https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L14
 static inline VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv, int call_status);
 static inline VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const NODE *cref);
 static inline VALUE vm_yield(rb_thread_t *th, int argc, const VALUE *argv);
+static inline VALUE vm_yield_with_block(rb_thread_t *th, int argc, const VALUE *argv, const rb_block_t *blockargptr);
 static NODE *vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr);
 static VALUE vm_exec(rb_thread_t *th);
 static void vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref, rb_block_t *base_block);
@@ -988,6 +989,16 @@ rb_yield_splat(VALUE values) https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L989
     return v;
 }
 
+VALUE
+rb_yield_block(VALUE val, VALUE arg, int argc, const VALUE *argv, VALUE blockarg)
+{
+    const rb_block_t *blockptr = 0;
+    if (!NIL_P(blockarg)) {
+	rb_notimplement();
+    }
+    return vm_yield_with_block(GET_THREAD(), argc, argv, blockptr);
+}
+
 static VALUE
 loop_i(void)
 {
Index: range.c
===================================================================
--- range.c	(revision 43911)
+++ range.c	(revision 43912)
@@ -796,7 +796,7 @@ range_each(VALUE range) https://github.com/ruby/ruby/blob/trunk/range.c#L796
 
 	    args[0] = end;
 	    args[1] = EXCL(range) ? Qtrue : Qfalse;
-	    rb_block_call(tmp, rb_intern("upto"), 2, args, rb_yield, 0);
+	    rb_block_call(tmp, rb_intern("upto"), 2, args, rb_yield_block, 0);
 	}
 	else {
 	    if (!discrete_object_p(beg)) {
Index: vm.c
===================================================================
--- vm.c	(revision 43911)
+++ vm.c	(revision 43912)
@@ -699,6 +699,14 @@ vm_yield(rb_thread_t *th, int argc, cons https://github.com/ruby/ruby/blob/trunk/vm.c#L699
 			       blockptr->klass);
 }
 
+static inline VALUE
+vm_yield_with_block(rb_thread_t *th, int argc, const VALUE *argv, const rb_block_t *blockargptr)
+{
+    const rb_block_t *blockptr = check_block(th);
+    return invoke_block_from_c(th, blockptr, blockptr->self, argc, argv, blockargptr, 0,
+			       blockptr->klass);
+}
+
 static VALUE
 vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self, VALUE defined_class,
 	       int argc, const VALUE *argv, const rb_block_t *blockptr)

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

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