summaryrefslogtreecommitdiff
path: root/proc.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-26 07:55:12 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-26 07:55:12 +0000
commitbbe36f64a065dd6124b119590c5d4e5370c893e5 (patch)
tree5c6ba2393f917742f9d0d5a1badeffb4bb62023a /proc.c
parentf8665e42f01f5caff4cb90e1ba0893a8518d521f (diff)
merge revision(s) 41342,41359,41361: [Backport #8341]
test/ruby/test_proc.rb: tests for [Bug #8341] * include/ruby/intern.h, proc.c (rb_method_call_with_block): new function to invoke a Method object with a block passed as an argument. * proc.c (bmcall): use the above function to avoid a block sharing. [ruby-core:54626] [Bug #8341] * test/ruby/test_proc.rb (TestProc#test_block_persist_between_calls): run related tests. * test/ruby/test_proc.rb (TestProc#test_block_given_method_to_proc): run test for r41359. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@41650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/proc.c b/proc.c
index fdd148ebe9..ca6d3c4769 100644
--- a/proc.c
+++ b/proc.c
@@ -27,7 +27,7 @@ VALUE rb_cMethod;
VALUE rb_cBinding;
VALUE rb_cProc;
-static VALUE bmcall(VALUE, VALUE);
+static VALUE bmcall(VALUE, VALUE, int, VALUE *, VALUE);
static int method_arity(VALUE);
/* Proc */
@@ -1407,6 +1407,13 @@ method_clone(VALUE self)
VALUE
rb_method_call(int argc, VALUE *argv, VALUE method)
{
+ VALUE proc = rb_block_given_p() ? rb_block_proc() : Qnil;
+ return rb_method_call_with_block(argc, argv, method, proc);
+}
+
+VALUE
+rb_method_call_with_block(int argc, VALUE *argv, VALUE method, VALUE pass_procval)
+{
VALUE result = Qnil; /* OK */
struct METHOD *data;
int state;
@@ -1425,8 +1432,15 @@ rb_method_call(int argc, VALUE *argv, VALUE method)
}
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;
+ }
- PASS_PASSED_BLOCK_TH(th);
+ th->passed_block = block;
result = rb_vm_call(th, data->recv, data->id, argc, argv, data->me);
}
POP_TAG();
@@ -1802,11 +1816,10 @@ mlambda(VALUE method)
}
static VALUE
-bmcall(VALUE args, VALUE method)
+bmcall(VALUE args, VALUE method, int argc, VALUE *argv, VALUE passed_proc)
{
volatile VALUE a;
VALUE ret;
- int argc;
if (CLASS_OF(args) != rb_cArray) {
args = rb_ary_new3(1, args);
@@ -1815,7 +1828,7 @@ bmcall(VALUE args, VALUE method)
else {
argc = check_argc(RARRAY_LEN(args));
}
- ret = rb_method_call(argc, RARRAY_PTR(args), method);
+ ret = rb_method_call_with_block(argc, RARRAY_PTR(args), method, passed_proc);
RB_GC_GUARD(a) = args;
return ret;
}