diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-26 08:32:49 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-26 08:32:49 +0000 |
commit | 837fd5e494731d7d44786f29e7d6e8c27029806f (patch) | |
tree | 7ccbb6b6733ccb07c28b7df28e3e2a6b604cc731 /vm_eval.c | |
parent | 07f04f468d729b399b794198c61516f2e8ac0a89 (diff) | |
download | bundler-837fd5e494731d7d44786f29e7d6e8c27029806f.tar.gz |
Use rb_execution_context_t instead of rb_thread_t
to represent execution context [Feature #14038]
* vm_core.h (rb_thread_t): rb_thread_t::ec is now a pointer.
There are many code using `th` to represent execution context
(such as cfp, VM stack and so on). To access `ec`, they need to
use `th->ec->...` (adding one indirection) so that we need to
replace them by passing `ec` instead of `th`.
* vm_core.h (GET_EC()): introduced to access current ec. Also
remove `ruby_current_thread` global variable.
* cont.c (rb_context_t): introduce rb_context_t::thread_ptr instead of
rb_context_t::thread_value.
* cont.c (ec_set_vm_stack): added to update vm_stack explicitly.
* cont.c (ec_switch): added to switch ec explicitly.
* cont.c (rb_fiber_close): added to terminate fibers explicitly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_eval.c')
-rw-r--r-- | vm_eval.c | 62 |
1 files changed, 31 insertions, 31 deletions
@@ -74,7 +74,7 @@ vm_call0_cfunc_with_frame(rb_thread_t* th, struct rb_calling_info *calling, cons RUBY_DTRACE_CMETHOD_ENTRY_HOOK(th, me->owner, me->def->original_id); EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->def->original_id, mid, me->owner, Qnil); { - rb_control_frame_t *reg_cfp = th->ec.cfp; + rb_control_frame_t *reg_cfp = th->ec->cfp; vm_push_frame(th, 0, VM_FRAME_MAGIC_CFUNC | VM_FRAME_FLAG_CFRAME | VM_ENV_FLAG_LOCAL, recv, block_handler, (VALUE)me, @@ -113,7 +113,7 @@ vm_call0_body(rb_thread_t* th, struct rb_calling_info *calling, const struct rb_ switch (cc->me->def->type) { case VM_METHOD_TYPE_ISEQ: { - rb_control_frame_t *reg_cfp = th->ec.cfp; + rb_control_frame_t *reg_cfp = th->ec->cfp; int i; CHECK_VM_STACK_OVERFLOW(reg_cfp, calling->argc + 1); @@ -124,7 +124,7 @@ vm_call0_body(rb_thread_t* th, struct rb_calling_info *calling, const struct rb_ } vm_call_iseq_setup(th, reg_cfp, calling, ci, cc); - VM_ENV_FLAGS_SET(th->ec.cfp->ep, VM_FRAME_FLAG_FINISH); + VM_ENV_FLAGS_SET(th->ec->cfp->ep, VM_FRAME_FLAG_FINISH); return vm_exec(th); /* CHECK_INTS in this function */ } case VM_METHOD_TYPE_NOTIMPLEMENTED: @@ -211,10 +211,10 @@ rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc, const VALUE *argv, c static inline VALUE vm_call_super(rb_thread_t *th, int argc, const VALUE *argv) { - VALUE recv = th->ec.cfp->self; + VALUE recv = th->ec->cfp->self; VALUE klass; ID id; - rb_control_frame_t *cfp = th->ec.cfp; + rb_control_frame_t *cfp = th->ec->cfp; const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp); if (VM_FRAME_RUBYFRAME_P(cfp)) { @@ -247,7 +247,7 @@ rb_current_receiver(void) { rb_thread_t *th = GET_THREAD(); rb_control_frame_t *cfp; - if (!th || !(cfp = th->ec.cfp)) + if (!th || !(cfp = th->ec->cfp)) rb_raise(rb_eRuntimeError, "no self, no life"); return cfp->self; } @@ -348,7 +348,7 @@ check_funcall_respond_to(rb_thread_t *th, VALUE klass, VALUE recv, ID mid) static int check_funcall_callable(rb_thread_t *th, const rb_callable_method_entry_t *me) { - return rb_method_call_status(th, me, CALL_FCALL, th->ec.cfp->self) == MISSING_NONE; + return rb_method_call_status(th, me, CALL_FCALL, th->ec->cfp->self) == MISSING_NONE; } static VALUE @@ -585,7 +585,7 @@ static inline VALUE rb_call(VALUE recv, ID mid, int argc, const VALUE *argv, call_type scope) { rb_thread_t *th = GET_THREAD(); - return rb_call0(recv, mid, argc, argv, scope, th->ec.cfp->self); + return rb_call0(recv, mid, argc, argv, scope, th->ec->cfp->self); } NORETURN(static void raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, @@ -850,7 +850,7 @@ rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE pas static VALUE * current_vm_stack_arg(rb_thread_t *th, const VALUE *argv) { - rb_control_frame_t *prev_cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->ec.cfp); + rb_control_frame_t *prev_cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->ec->cfp); if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, prev_cfp)) return NULL; if (prev_cfp->sp + 1 != argv) return NULL; return prev_cfp->sp + 1; @@ -869,7 +869,7 @@ send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope) self = Qundef; } else { - self = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->ec.cfp)->self; + self = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->ec->cfp)->self; } if (argc == 0) { @@ -1112,7 +1112,7 @@ rb_iterate0(VALUE (* it_proc) (VALUE), VALUE data1, { enum ruby_tag_type state; volatile VALUE retval = Qnil; - rb_control_frame_t *const cfp = th->ec.cfp; + rb_control_frame_t *const cfp = th->ec->cfp; TH_PUSH_TAG(th); state = TH_EXEC_TAG(); @@ -1134,15 +1134,15 @@ rb_iterate0(VALUE (* it_proc) (VALUE), VALUE data1, retval = (*it_proc) (data1); } else if (state == TAG_BREAK || state == TAG_RETRY) { - const struct vm_throw_data *const err = (struct vm_throw_data *)th->ec.errinfo; + const struct vm_throw_data *const err = (struct vm_throw_data *)th->ec->errinfo; const rb_control_frame_t *const escape_cfp = THROW_DATA_CATCH_FRAME(err); if (cfp == escape_cfp) { rb_vm_rewind_cfp(th, cfp); state = 0; - th->ec.tag->state = TAG_NONE; - th->ec.errinfo = Qnil; + th->ec->tag->state = TAG_NONE; + th->ec->errinfo = Qnil; if (state == TAG_RETRY) goto iter_retry; retval = THROW_DATA_VAL(err); @@ -1296,7 +1296,7 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_ base_block = &bind->block; } else { - rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->ec.cfp); + rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->ec->cfp); if (cfp != 0) { block.as.captured = *VM_CFP_TO_CAPTURED_BLOCK(cfp); @@ -1318,7 +1318,7 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_ iseq = rb_iseq_compile_with_option(src, fname, realpath, INT2FIX(line), base_block, Qnil); if (!iseq) { - rb_exc_raise(adjust_backtrace_in_eval(th, th->ec.errinfo)); + rb_exc_raise(adjust_backtrace_in_eval(th, th->ec->errinfo)); } /* TODO: what the code checking? */ @@ -1340,7 +1340,7 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_ /* save new env */ if (bind && iseq->body->local_table_size > 0) { - vm_bind_update_env(scope, bind, vm_make_env_object(th, th->ec.cfp)); + vm_bind_update_env(scope, bind, vm_make_env_object(th, th->ec->cfp)); } } @@ -1357,7 +1357,7 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_ if (state) { if (state == TAG_RAISE) { - adjust_backtrace_in_eval(th, th->ec.errinfo); + adjust_backtrace_in_eval(th, th->ec->errinfo); } TH_JUMP_TAG(th, state); } @@ -1546,7 +1546,7 @@ static VALUE yield_under(VALUE under, VALUE self, int argc, const VALUE *argv) { rb_thread_t *th = GET_THREAD(); - rb_control_frame_t *cfp = th->ec.cfp; + rb_control_frame_t *cfp = th->ec->cfp; VALUE block_handler = VM_CF_BLOCK_HANDLER(cfp); VALUE new_block_handler = 0; const struct rb_captured_block *captured = NULL; @@ -1580,7 +1580,7 @@ yield_under(VALUE under, VALUE self, int argc, const VALUE *argv) new_captured.self = self; ep = captured->ep; - VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(th->ec.cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler); + VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(th->ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler); } cref = vm_cref_push(th, under, ep, TRUE); @@ -1591,7 +1591,7 @@ VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements) { rb_thread_t *th = GET_THREAD(); - VALUE block_handler = VM_CF_BLOCK_HANDLER(th->ec.cfp); + VALUE block_handler = VM_CF_BLOCK_HANDLER(th->ec->cfp); if (vm_block_handler_type(block_handler) != block_handler_type_iseq) { rb_bug("rb_yield_refine_block: an iseq block is required"); @@ -1603,7 +1603,7 @@ rb_yield_refine_block(VALUE refinement, VALUE refinements) const VALUE *ep = captured->ep; rb_cref_t *cref = vm_cref_push(th, refinement, ep, TRUE); CREF_REFINEMENTS_SET(cref, refinements); - VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(th->ec.cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler); + VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(th->ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler); new_captured.self = refinement; return vm_yield_with_cref(th, 0, NULL, cref, FALSE); } @@ -1875,7 +1875,7 @@ void rb_throw_obj(VALUE tag, VALUE value) { rb_thread_t *th = GET_THREAD(); - struct rb_vm_tag *tt = th->ec.tag; + struct rb_vm_tag *tt = th->ec->tag; while (tt) { if (tt->tag == tag) { @@ -1892,7 +1892,7 @@ rb_throw_obj(VALUE tag, VALUE value) rb_exc_raise(rb_class_new_instance(numberof(desc), desc, rb_eUncaughtThrow)); } - th->ec.errinfo = (VALUE)THROW_DATA_NEW(tag, NULL, TAG_THROW); + th->ec->errinfo = (VALUE)THROW_DATA_NEW(tag, NULL, TAG_THROW); TH_JUMP_TAG(th, TAG_THROW); } @@ -1986,7 +1986,7 @@ vm_catch_protect(VALUE tag, rb_block_call_func *func, VALUE data, { enum ruby_tag_type state; VALUE val = Qnil; /* OK */ - rb_control_frame_t *volatile saved_cfp = th->ec.cfp; + rb_control_frame_t *volatile saved_cfp = th->ec->cfp; TH_PUSH_TAG(th); @@ -1996,10 +1996,10 @@ vm_catch_protect(VALUE tag, rb_block_call_func *func, VALUE data, /* call with argc=1, argv = [tag], block = Qnil to insure compatibility */ val = (*func)(tag, data, 1, (const VALUE *)&tag, Qnil); } - else if (state == TAG_THROW && THROW_DATA_VAL((struct vm_throw_data *)th->ec.errinfo) == tag) { + else if (state == TAG_THROW && THROW_DATA_VAL((struct vm_throw_data *)th->ec->errinfo) == tag) { rb_vm_rewind_cfp(th, saved_cfp); - val = th->ec.tag->retval; - th->ec.errinfo = Qnil; + val = th->ec->tag->retval; + th->ec->errinfo = Qnil; state = 0; } TH_POP_TAG(); @@ -2081,7 +2081,7 @@ rb_f_local_variables(void) struct local_var_list vars; rb_thread_t *th = GET_THREAD(); rb_control_frame_t *cfp = - vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(th->ec.cfp)); + vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(th->ec->cfp)); unsigned int i; local_var_list_init(&vars); @@ -2137,7 +2137,7 @@ VALUE rb_f_block_given_p(void) { rb_thread_t *th = GET_THREAD(); - rb_control_frame_t *cfp = th->ec.cfp; + rb_control_frame_t *cfp = th->ec->cfp; cfp = vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)); if (cfp != NULL && VM_CF_BLOCK_HANDLER(cfp) != VM_BLOCK_HANDLER_NONE) { @@ -2152,7 +2152,7 @@ VALUE rb_current_realfilepath(void) { rb_thread_t *th = GET_THREAD(); - rb_control_frame_t *cfp = th->ec.cfp; + rb_control_frame_t *cfp = th->ec->cfp; cfp = vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)); if (cfp != 0) return rb_iseq_realpath(cfp->iseq); return Qnil; |