From 1720a5bac44b590205257cf3acd0a3071738e6ec Mon Sep 17 00:00:00 2001 From: ktsj Date: Mon, 17 Jun 2013 12:38:52 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 12 ++++++++++++ include/ruby/intern.h | 1 + proc.c | 23 ++++++++++++++++++----- test/ruby/test_proc.rb | 1 - 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index f3739aae8d..3ed7df09c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Mon Jun 17 21:33:27 2013 Kazuki Tsujimoto + + * 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. + Mon Jun 17 20:53:21 2013 Tanaka Akira * loadpath.c (RUBY_REVISION): Defined to suppress revision.h diff --git a/include/ruby/intern.h b/include/ruby/intern.h index fb989ef2c7..5c588929d1 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -380,6 +380,7 @@ VALUE rb_binding_new(void); VALUE rb_obj_method(VALUE, VALUE); VALUE rb_obj_is_method(VALUE); VALUE rb_method_call(int, VALUE*, VALUE); +VALUE rb_method_call_with_block(int, VALUE *, VALUE, VALUE); int rb_mod_method_arity(VALUE, ID); int rb_obj_method_arity(VALUE, ID); VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*); diff --git a/proc.c b/proc.c index fa30463f9e..0a5bda385e 100644 --- a/proc.c +++ b/proc.c @@ -28,7 +28,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); static int method_min_max_arity(VALUE, int *max); #define attached id__attached__ @@ -1592,6 +1592,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; @@ -1612,8 +1619,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; - PASS_PASSED_BLOCK_TH(th); + if (!NIL_P(pass_procval)) { + rb_proc_t *pass_proc; + GetProcPtr(pass_procval, pass_proc); + block = &pass_proc->block; + } + + th->passed_block = block; result = rb_vm_call(th, data->recv, data->id, argc, argv, data->me, data->defined_class); } POP_TAG(); @@ -2062,11 +2076,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); @@ -2075,7 +2088,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; } diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 57f28dafeb..c5352e342e 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -200,7 +200,6 @@ class TestProc < Test::Unit::TestCase def test_block_persist_between_calls bug8341 = '[Bug #8341]' - skip bug8341 o = Object.new def o.m1(top=true) if top