diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-13 09:48:08 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-13 09:48:08 +0000 |
commit | 0c1682b3045a04f753f81d0a5d18c303dd9496ba (patch) | |
tree | 9bcfc049d17042945000c0d9735a987573dbd2c7 | |
parent | 684aa1f98590ca97eab22ceecfea04c5cb5134bf (diff) | |
download | bundler-0c1682b3045a04f753f81d0a5d18c303dd9496ba.tar.gz |
* vm_insnhelper.c (vm_call_cfunc_with_frame): don't use ci after
EXEC_EVENT_HOOK because ci can be overridden.
* vm_eval.c: ditto.
* method.h: change invoker's parameters types.
* vm_method.c (call_cfunc_invoker_func): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37647 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | method.h | 2 | ||||
-rw-r--r-- | vm_eval.c | 32 | ||||
-rw-r--r-- | vm_insnhelper.c | 87 | ||||
-rw-r--r-- | vm_method.c | 2 |
5 files changed, 77 insertions, 57 deletions
@@ -1,3 +1,14 @@ +Tue Nov 13 18:44:01 2012 Koichi Sasada <ko1@atdot.net> + + * vm_insnhelper.c (vm_call_cfunc_with_frame): don't use ci after + EXEC_EVENT_HOOK because ci can be overridden. + + * vm_eval.c: ditto. + + * method.h: change invoker's parameters types. + + * vm_method.c (call_cfunc_invoker_func): ditto. + Tue Nov 13 18:01:54 2012 Shugo Maeda <shugo@ruby-lang.org> * eval.c (rb_mod_using): raise an ArgumentError if cyclic using is @@ -49,7 +49,7 @@ struct rb_call_info_struct; typedef struct rb_method_cfunc_struct { VALUE (*func)(ANYARGS); - VALUE (*invoker)(VALUE (*func)(ANYARGS), const struct rb_call_info_struct *ci, const VALUE *argv); + VALUE (*invoker)(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv); int argc; } rb_method_cfunc_t; @@ -94,23 +94,27 @@ static VALUE vm_call0_cfunc_with_frame(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv) { VALUE val; - - RUBY_DTRACE_FUNC_ENTRY_HOOK(ci->defined_class, ci->mid); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, ci->recv, ci->mid, ci->defined_class); + const rb_method_entry_t *me = ci->me; + const rb_method_cfunc_t *cfunc = &me->def->body.cfunc; + int len = cfunc->argc; + VALUE recv = ci->recv; + VALUE defined_class = ci->defined_class; + int argc = ci->argc; + ID mid = ci->mid; + rb_block_t *blockptr = ci->blockptr; + + RUBY_DTRACE_FUNC_ENTRY_HOOK(defined_class, mid); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, mid, defined_class); { rb_control_frame_t *reg_cfp = th->cfp; - const rb_method_entry_t *me = ci->me; - const rb_method_cfunc_t *cfunc = &me->def->body.cfunc; - int len = cfunc->argc; - vm_push_frame(th, 0, VM_FRAME_MAGIC_CFUNC, - ci->recv, ci->defined_class, VM_ENVVAL_BLOCK_PTR(ci->blockptr), - 0, reg_cfp->sp, 1, ci->me); + vm_push_frame(th, 0, VM_FRAME_MAGIC_CFUNC, recv, defined_class, + VM_ENVVAL_BLOCK_PTR(blockptr), 0, reg_cfp->sp, 1, me); - if (len >= 0) rb_check_arity(ci->argc, len, len); + if (len >= 0) rb_check_arity(argc, len, len); VM_PROFILE_UP(2); - val = (*cfunc->invoker)(cfunc->func, ci, argv); + val = (*cfunc->invoker)(cfunc->func, recv, argc, argv); if (UNLIKELY(reg_cfp != th->cfp + 1)) { rb_bug("vm_call0_cfunc_with_frame: cfp consistency error"); @@ -118,8 +122,8 @@ vm_call0_cfunc_with_frame(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv VM_PROFILE_UP(3); vm_pop_frame(th); } - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, ci->recv, ci->mid, ci->defined_class); - RUBY_DTRACE_FUNC_RETURN_HOOK(ci->defined_class, ci->mid); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, mid, defined_class); + RUBY_DTRACE_FUNC_RETURN_HOOK(defined_class, mid); return val; } @@ -212,7 +216,7 @@ vm_call0_body(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv) { /* TODO: can optimize it */ const rb_method_cfunc_t *cfunc = &ci->me->def->body.cfunc; - return cfunc->invoker(cfunc->func, ci, argv); + return cfunc->invoker(cfunc->func, ci->recv, ci->argc, argv); } case VM_METHOD_TYPE_UNDEF: break; diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 3e1ca3866c..bf524d6fb8 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1306,111 +1306,111 @@ vm_call_iseq_setup_tailcall(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_in } static VALUE -call_cfunc_m2(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_m2(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, rb_ary_new4(ci->argc, argv)); + return (*func)(recv, rb_ary_new4(argc, argv)); } static VALUE -call_cfunc_m1(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_m1(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->argc, argv, ci->recv); + return (*func)(argc, argv, recv); } static VALUE -call_cfunc_0(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_0(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv); + return (*func)(recv); } static VALUE -call_cfunc_1(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_1(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0]); + return (*func)(recv, argv[0]); } static VALUE -call_cfunc_2(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_2(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1]); + return (*func)(recv, argv[0], argv[1]); } static VALUE -call_cfunc_3(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_3(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2]); + return (*func)(recv, argv[0], argv[1], argv[2]); } static VALUE -call_cfunc_4(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_4(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2], argv[3]); + return (*func)(recv, argv[0], argv[1], argv[2], argv[3]); } static VALUE -call_cfunc_5(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_5(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2], argv[3], argv[4]); + return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4]); } static VALUE -call_cfunc_6(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_6(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); + return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); } static VALUE -call_cfunc_7(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_7(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); + return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); } static VALUE -call_cfunc_8(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_8(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]); + return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]); } static VALUE -call_cfunc_9(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_9(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); + return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); } static VALUE -call_cfunc_10(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_10(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); + return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); } static VALUE -call_cfunc_11(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_11(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10]); + return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10]); } static VALUE -call_cfunc_12(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_12(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11]); + return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11]); } static VALUE -call_cfunc_13(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_13(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12]); + return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12]); } static VALUE -call_cfunc_14(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_14(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13]); + return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13]); } static VALUE -call_cfunc_15(VALUE (*func)(ANYARGS), const rb_call_info_t *ci, const VALUE *argv) +call_cfunc_15(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) { - return (*func)(ci->recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14]); + return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14]); } #ifndef VM_PROFILE @@ -1441,19 +1441,24 @@ vm_call_cfunc_with_frame(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_i const rb_method_entry_t *me = ci->me; const rb_method_cfunc_t *cfunc = &me->def->body.cfunc; int len = cfunc->argc; + + /* don't use `ci' after EXEC_EVENT_HOOK because ci can be override */ VALUE recv = ci->recv; + VALUE defined_class = ci->defined_class; + rb_block_t *blockptr = ci->blockptr; + int argc = ci->argc; RUBY_DTRACE_FUNC_ENTRY_HOOK(me->klass, me->called_id); EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->called_id, me->klass); - vm_push_frame(th, 0, VM_FRAME_MAGIC_CFUNC, recv, ci->defined_class, - VM_ENVVAL_BLOCK_PTR(ci->blockptr), 0, th->cfp->sp, 1, me); + vm_push_frame(th, 0, VM_FRAME_MAGIC_CFUNC, recv, defined_class, + VM_ENVVAL_BLOCK_PTR(blockptr), 0, th->cfp->sp, 1, me); - if (len >= 0) rb_check_arity(ci->argc, len, len); + if (len >= 0) rb_check_arity(argc, len, len); - reg_cfp->sp -= ci->argc + 1; + reg_cfp->sp -= argc + 1; VM_PROFILE_UP(0); - val = (*cfunc->invoker)(cfunc->func, ci, reg_cfp->sp + 1); + val = (*cfunc->invoker)(cfunc->func, recv, argc, reg_cfp->sp + 1); if (reg_cfp != th->cfp + 1) { rb_bug("vm_call_cfunc - cfp consistency error"); diff --git a/vm_method.c b/vm_method.c index ca521563e5..6580bb6028 100644 --- a/vm_method.c +++ b/vm_method.c @@ -299,7 +299,7 @@ method_added(VALUE klass, ID mid) } static VALUE -(*call_cfunc_invoker_func(int argc))(VALUE (*func)(ANYARGS), const rb_call_info_t *, const VALUE *) +(*call_cfunc_invoker_func(int argc))(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *) { switch (argc) { case -2: return call_cfunc_m2; |