th -> ec for method management functions.

* vm_eval.c: `th` -> `ec` for the following functions:
  * check_funcall_respond_to
  * check_funcall_callable
  * check_funcall_missing
  * rb_method_call_status

* vm_method.c: ditto.
  * call_method_entry
  * basic_obj_respond_to_missing
  * basic_obj_respond_to
  * vm_respond_to

* vm_eval.c (stack_check): accepts `ec` instead of `th`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2017-10-28 12:23:51 +00:00
parent ed21061f21
commit 7fa4beba91
3 changed files with 48 additions and 47 deletions

3
vm.c
View File

@ -1013,7 +1013,6 @@ invoke_iseq_block_from_c(rb_execution_context_t *ec, const struct rb_captured_bl
VALUE self, int argc, const VALUE *argv, VALUE passed_block_handler, VALUE self, int argc, const VALUE *argv, VALUE passed_block_handler,
const rb_cref_t *cref, int is_lambda) const rb_cref_t *cref, int is_lambda)
{ {
rb_thread_t *th = rb_ec_thread_ptr(ec);
const rb_iseq_t *iseq = rb_iseq_check(captured->code.iseq); const rb_iseq_t *iseq = rb_iseq_check(captured->code.iseq);
int i, opt_pc; int i, opt_pc;
VALUE type = VM_FRAME_MAGIC_BLOCK | (is_lambda ? VM_FRAME_FLAG_LAMBDA : 0); VALUE type = VM_FRAME_MAGIC_BLOCK | (is_lambda ? VM_FRAME_FLAG_LAMBDA : 0);
@ -1021,7 +1020,7 @@ invoke_iseq_block_from_c(rb_execution_context_t *ec, const struct rb_captured_bl
VALUE *sp = cfp->sp; VALUE *sp = cfp->sp;
const rb_callable_method_entry_t *me = ec->passed_bmethod_me; const rb_callable_method_entry_t *me = ec->passed_bmethod_me;
ec->passed_bmethod_me = NULL; ec->passed_bmethod_me = NULL;
stack_check(th); stack_check(ec);
CHECK_VM_STACK_OVERFLOW(cfp, argc); CHECK_VM_STACK_OVERFLOW(cfp, argc);
cfp->sp = sp + argc; cfp->sp = sp + argc;

View File

@ -252,8 +252,10 @@ rb_current_receiver(void)
} }
static inline void static inline void
stack_check(rb_thread_t *th) stack_check(rb_execution_context_t *ec)
{ {
rb_thread_t *th = rb_ec_thread_ptr(ec);
if (!rb_thread_raised_p(th, RAISED_STACKOVERFLOW) && if (!rb_thread_raised_p(th, RAISED_STACKOVERFLOW) &&
rb_threadptr_stack_check(th)) { rb_threadptr_stack_check(th)) {
rb_thread_raised_set(th, RAISED_STACKOVERFLOW); rb_thread_raised_set(th, RAISED_STACKOVERFLOW);
@ -262,7 +264,7 @@ stack_check(rb_thread_t *th)
} }
static inline const rb_callable_method_entry_t *rb_search_method_entry(VALUE recv, ID mid); static inline const rb_callable_method_entry_t *rb_search_method_entry(VALUE recv, ID mid);
static inline enum method_missing_reason rb_method_call_status(rb_thread_t *th, const rb_callable_method_entry_t *me, call_type scope, VALUE self); static inline enum method_missing_reason rb_method_call_status(rb_execution_context_t *ec, const rb_callable_method_entry_t *me, call_type scope, VALUE self);
/*! /*!
* \internal * \internal
@ -284,14 +286,14 @@ rb_call0(VALUE recv, ID mid, int argc, const VALUE *argv,
call_type scope, VALUE self) call_type scope, VALUE self)
{ {
const rb_callable_method_entry_t *me = rb_search_method_entry(recv, mid); const rb_callable_method_entry_t *me = rb_search_method_entry(recv, mid);
rb_thread_t *th = GET_THREAD(); rb_execution_context_t *ec = GET_EC();
enum method_missing_reason call_status = rb_method_call_status(th, me, scope, self); enum method_missing_reason call_status = rb_method_call_status(ec, me, scope, self);
if (call_status != MISSING_NONE) { if (call_status != MISSING_NONE) {
return method_missing(recv, mid, argc, argv, call_status); return method_missing(recv, mid, argc, argv, call_status);
} }
stack_check(th); stack_check(ec);
return vm_call0(th->ec, recv, mid, argc, argv, me); return vm_call0(ec, recv, mid, argc, argv, me);
} }
struct rescue_funcall_args { struct rescue_funcall_args {
@ -309,7 +311,7 @@ struct rescue_funcall_args {
static VALUE static VALUE
check_funcall_exec(struct rescue_funcall_args *args) check_funcall_exec(struct rescue_funcall_args *args)
{ {
return call_method_entry(args->th, args->defined_class, return call_method_entry(args->th->ec, args->defined_class,
args->recv, idMethodMissing, args->recv, idMethodMissing,
args->me, args->argc, args->argv); args->me, args->argc, args->argv);
} }
@ -339,25 +341,25 @@ check_funcall_failed(struct rescue_funcall_args *args, VALUE e)
} }
static int static int
check_funcall_respond_to(rb_thread_t *th, VALUE klass, VALUE recv, ID mid) check_funcall_respond_to(rb_execution_context_t *ec, VALUE klass, VALUE recv, ID mid)
{ {
return vm_respond_to(th, klass, recv, mid, TRUE); return vm_respond_to(ec, klass, recv, mid, TRUE);
} }
static int static int
check_funcall_callable(rb_thread_t *th, const rb_callable_method_entry_t *me) check_funcall_callable(rb_execution_context_t *ec, 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(ec, me, CALL_FCALL, ec->cfp->self) == MISSING_NONE;
} }
static VALUE static VALUE
check_funcall_missing(rb_thread_t *th, VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int respond, VALUE def) check_funcall_missing(rb_execution_context_t *ec, VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int respond, VALUE def)
{ {
struct rescue_funcall_args args; struct rescue_funcall_args args;
const rb_method_entry_t *me; const rb_method_entry_t *me;
VALUE ret = Qundef; VALUE ret = Qundef;
ret = basic_obj_respond_to_missing(th, klass, recv, ret = basic_obj_respond_to_missing(ec, klass, recv,
ID2SYM(mid), Qtrue); ID2SYM(mid), Qtrue);
if (!RTEST(ret)) return def; if (!RTEST(ret)) return def;
args.respond = respond > 0; args.respond = respond > 0;
@ -369,8 +371,8 @@ check_funcall_missing(rb_thread_t *th, VALUE klass, VALUE recv, ID mid, int argc
new_args[0] = ID2SYM(mid); new_args[0] = ID2SYM(mid);
MEMCPY(new_args+1, argv, VALUE, argc); MEMCPY(new_args+1, argv, VALUE, argc);
th->method_missing_reason = MISSING_NOENTRY; rb_ec_thread_ptr(ec)->method_missing_reason = MISSING_NOENTRY;
args.th = th; args.th = rb_ec_thread_ptr(ec);
args.recv = recv; args.recv = recv;
args.me = me; args.me = me;
args.mid = mid; args.mid = mid;
@ -395,21 +397,21 @@ rb_check_funcall_default(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE
{ {
VALUE klass = CLASS_OF(recv); VALUE klass = CLASS_OF(recv);
const rb_callable_method_entry_t *me; const rb_callable_method_entry_t *me;
rb_thread_t *th = GET_THREAD(); rb_execution_context_t *ec = GET_EC();
int respond = check_funcall_respond_to(th, klass, recv, mid); int respond = check_funcall_respond_to(ec, klass, recv, mid);
if (!respond) if (!respond)
return def; return def;
me = rb_search_method_entry(recv, mid); me = rb_search_method_entry(recv, mid);
if (!check_funcall_callable(th, me)) { if (!check_funcall_callable(ec, me)) {
VALUE ret = check_funcall_missing(th, klass, recv, mid, argc, argv, VALUE ret = check_funcall_missing(ec, klass, recv, mid, argc, argv,
respond, def); respond, def);
if (ret == Qundef) ret = def; if (ret == Qundef) ret = def;
return ret; return ret;
} }
stack_check(th); stack_check(ec);
return vm_call0(th->ec, recv, mid, argc, argv, me); return vm_call0(ec, recv, mid, argc, argv, me);
} }
VALUE VALUE
@ -418,8 +420,8 @@ rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv,
{ {
VALUE klass = CLASS_OF(recv); VALUE klass = CLASS_OF(recv);
const rb_callable_method_entry_t *me; const rb_callable_method_entry_t *me;
rb_thread_t *th = GET_THREAD(); rb_execution_context_t *ec = GET_EC();
int respond = check_funcall_respond_to(th, klass, recv, mid); int respond = check_funcall_respond_to(ec, klass, recv, mid);
if (!respond) { if (!respond) {
(*hook)(FALSE, recv, mid, argc, argv, arg); (*hook)(FALSE, recv, mid, argc, argv, arg);
@ -427,15 +429,15 @@ rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv,
} }
me = rb_search_method_entry(recv, mid); me = rb_search_method_entry(recv, mid);
if (!check_funcall_callable(th, me)) { if (!check_funcall_callable(ec, me)) {
VALUE ret = check_funcall_missing(th, klass, recv, mid, argc, argv, VALUE ret = check_funcall_missing(ec, klass, recv, mid, argc, argv,
respond, Qundef); respond, Qundef);
(*hook)(ret != Qundef, recv, mid, argc, argv, arg); (*hook)(ret != Qundef, recv, mid, argc, argv, arg);
return ret; return ret;
} }
stack_check(th); stack_check(ec);
(*hook)(TRUE, recv, mid, argc, argv, arg); (*hook)(TRUE, recv, mid, argc, argv, arg);
return vm_call0(th->ec, recv, mid, argc, argv, me); return vm_call0(ec, recv, mid, argc, argv, me);
} }
static const char * static const char *
@ -524,7 +526,7 @@ rb_search_method_entry(VALUE recv, ID mid)
} }
static inline enum method_missing_reason static inline enum method_missing_reason
rb_method_call_status(rb_thread_t *th, const rb_callable_method_entry_t *me, call_type scope, VALUE self) rb_method_call_status(rb_execution_context_t *ec, const rb_callable_method_entry_t *me, call_type scope, VALUE self)
{ {
VALUE klass; VALUE klass;
ID oid; ID oid;
@ -673,7 +675,7 @@ raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, VALUE obj,
rb_obj_class(argv[0])); rb_obj_class(argv[0]));
} }
stack_check(th); stack_check(th->ec);
if (last_call_status & MISSING_PRIVATE) { if (last_call_status & MISSING_PRIVATE) {
format = rb_fstring_cstr("private method `%s' called for %s%s%s"); format = rb_fstring_cstr("private method `%s' called for %s%s%s");

View File

@ -1885,19 +1885,19 @@ rb_method_basic_definition_p(VALUE klass, ID id)
} }
static VALUE static VALUE
call_method_entry(rb_thread_t *th, VALUE defined_class, VALUE obj, ID id, call_method_entry(rb_execution_context_t *ec, VALUE defined_class, VALUE obj, ID id,
const rb_method_entry_t *me, int argc, const VALUE *argv) const rb_method_entry_t *me, int argc, const VALUE *argv)
{ {
const rb_callable_method_entry_t *cme = const rb_callable_method_entry_t *cme =
prepare_callable_method_entry(defined_class, id, me); prepare_callable_method_entry(defined_class, id, me);
VALUE passed_block_handler = vm_passed_block_handler(th->ec); VALUE passed_block_handler = vm_passed_block_handler(ec);
VALUE result = vm_call0(th->ec, obj, id, argc, argv, cme); VALUE result = vm_call0(ec, obj, id, argc, argv, cme);
vm_passed_block_handler_set(th->ec, passed_block_handler); vm_passed_block_handler_set(ec, passed_block_handler);
return result; return result;
} }
static VALUE static VALUE
basic_obj_respond_to_missing(rb_thread_t *th, VALUE klass, VALUE obj, basic_obj_respond_to_missing(rb_execution_context_t *ec, VALUE klass, VALUE obj,
VALUE mid, VALUE priv) VALUE mid, VALUE priv)
{ {
VALUE defined_class, args[2]; VALUE defined_class, args[2];
@ -1908,11 +1908,11 @@ basic_obj_respond_to_missing(rb_thread_t *th, VALUE klass, VALUE obj,
if (!me || METHOD_ENTRY_BASIC(me)) return Qundef; if (!me || METHOD_ENTRY_BASIC(me)) return Qundef;
args[0] = mid; args[0] = mid;
args[1] = priv; args[1] = priv;
return call_method_entry(th, defined_class, obj, rtmid, me, 2, args); return call_method_entry(ec, defined_class, obj, rtmid, me, 2, args);
} }
static inline int static inline int
basic_obj_respond_to(rb_thread_t *th, VALUE obj, ID id, int pub) basic_obj_respond_to(rb_execution_context_t *ec, VALUE obj, ID id, int pub)
{ {
VALUE klass = CLASS_OF(obj); VALUE klass = CLASS_OF(obj);
VALUE ret; VALUE ret;
@ -1921,7 +1921,7 @@ basic_obj_respond_to(rb_thread_t *th, VALUE obj, ID id, int pub)
case 2: case 2:
return FALSE; return FALSE;
case 0: case 0:
ret = basic_obj_respond_to_missing(th, klass, obj, ID2SYM(id), ret = basic_obj_respond_to_missing(ec, klass, obj, ID2SYM(id),
pub ? Qfalse : Qtrue); pub ? Qfalse : Qtrue);
return RTEST(ret) && ret != Qundef; return RTEST(ret) && ret != Qundef;
default: default:
@ -1930,7 +1930,7 @@ basic_obj_respond_to(rb_thread_t *th, VALUE obj, ID id, int pub)
} }
static int static int
vm_respond_to(rb_thread_t *th, VALUE klass, VALUE obj, ID id, int priv) vm_respond_to(rb_execution_context_t *ec, VALUE klass, VALUE obj, ID id, int priv)
{ {
VALUE defined_class; VALUE defined_class;
const ID resid = idRespond_to; const ID resid = idRespond_to;
@ -1975,7 +1975,7 @@ vm_respond_to(rb_thread_t *th, VALUE klass, VALUE obj, ID id, int priv)
} }
} }
} }
result = call_method_entry(th, defined_class, obj, resid, me, argc, args); result = call_method_entry(ec, defined_class, obj, resid, me, argc, args);
return RTEST(result); return RTEST(result);
} }
} }
@ -1983,10 +1983,10 @@ vm_respond_to(rb_thread_t *th, VALUE klass, VALUE obj, ID id, int priv)
int int
rb_obj_respond_to(VALUE obj, ID id, int priv) rb_obj_respond_to(VALUE obj, ID id, int priv)
{ {
rb_thread_t *th = GET_THREAD(); rb_execution_context_t *ec = GET_EC();
VALUE klass = CLASS_OF(obj); VALUE klass = CLASS_OF(obj);
int ret = vm_respond_to(th, klass, obj, id, priv); int ret = vm_respond_to(ec, klass, obj, id, priv);
if (ret == -1) ret = basic_obj_respond_to(th, obj, id, !priv); if (ret == -1) ret = basic_obj_respond_to(ec, obj, id, !priv);
return ret; return ret;
} }
@ -2022,16 +2022,16 @@ obj_respond_to(int argc, VALUE *argv, VALUE obj)
{ {
VALUE mid, priv; VALUE mid, priv;
ID id; ID id;
rb_thread_t *th = GET_THREAD(); rb_execution_context_t *ec = GET_EC();
rb_scan_args(argc, argv, "11", &mid, &priv); rb_scan_args(argc, argv, "11", &mid, &priv);
if (!(id = rb_check_id(&mid))) { if (!(id = rb_check_id(&mid))) {
VALUE ret = basic_obj_respond_to_missing(th, CLASS_OF(obj), obj, VALUE ret = basic_obj_respond_to_missing(ec, CLASS_OF(obj), obj,
rb_to_symbol(mid), priv); rb_to_symbol(mid), priv);
if (ret == Qundef) ret = Qfalse; if (ret == Qundef) ret = Qfalse;
return ret; return ret;
} }
if (basic_obj_respond_to(th, obj, id, !RTEST(priv))) if (basic_obj_respond_to(ec, obj, id, !RTEST(priv)))
return Qtrue; return Qtrue;
return Qfalse; return Qfalse;
} }