aboutsummaryrefslogtreecommitdiffstats
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-03 01:39:16 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-03 01:39:16 +0000
commit97119d8eb9ed654ba38cb3769c777bdb40492b1e (patch)
tree3d4e87205d6917410a460a99b6ad15a46beb0572 /vm_insnhelper.c
parent83c95981d9c9e4eabc5526f7d30d4c7137c585ec (diff)
downloadruby-97119d8eb9ed654ba38cb3769c777bdb40492b1e.tar.gz
* method.h: split rb_method_definition_t::flag to several flags.
`flag' contains several categories of attributes and it makes us confusion (at least, I had confused). * rb_method_visibility_t (flags::visi) * NOEX_UNDEF -> METHOD_VISI_UNDEF = 0 * NOEX_PUBLIC -> METHOD_VISI_PUBLIC = 1 * NOEX_PRIVATE -> METHOD_VISI_PRIVATE = 2 * NOEX_PROTECTED -> METHOD_VISI_PROTECTED = 3 * NOEX_SAFE(flag)) -> safe (flags::safe, 2 bits) * NOEX_BASIC -> basic (flags::basic, 1 bit) * NOEX_MODFUNC -> rb_scope_visibility_t in CREF * NOEX_SUPER -> MISSING_SUPER (enum missing_reason) * NOEX_VCALL -> MISSING_VCALL (enum missing_reason) * NOEX_RESPONDS -> BOUND_RESPONDS (macro) Now, NOEX_NOREDEF is not supported (I'm not sure it is needed). Background: I did not know what "NOEX" stands for. I asked Matz (who made this name) and his answer was "Nothing". "At first, it meant NO EXport (private), but the original meaning was gone." This is why I remove the mysterious word "NOEX" from MRI. * vm_core.h: introduce `enum missing_reason' to represent method_missing (NoMethodError) reason. * eval_intern.h: introduce rb_scope_visibility_t to represent scope visibility. It has 3 method visibilities (public/private/protected) and `module_function`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 64a23b7d80..87c9e5f739 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -487,7 +487,7 @@ rb_vm_rewrite_cref_stack(rb_cref_t *node, VALUE old_klass, VALUE new_klass, rb_c
}
static rb_cref_t *
-vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr)
+vm_cref_push(rb_thread_t *th, VALUE klass, rb_block_t *blockptr)
{
const rb_cref_t *prev_cref = NULL;
rb_cref_t *cref = NULL;
@@ -502,7 +502,7 @@ vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr)
prev_cref = vm_env_cref(cfp->ep);
}
}
- cref = vm_cref_new(klass, noex, prev_cref);
+ cref = vm_cref_new(klass, METHOD_VISI_PUBLIC, prev_cref);
/* TODO: why CREF_NEXT(cref) is 1? */
if (CREF_NEXT(cref) && CREF_NEXT(cref) != (void *) 1 &&
@@ -1315,7 +1315,7 @@ vm_callee_setup_arg(rb_thread_t *th, rb_call_info_t *ci, const rb_iseq_t *iseq,
CI_SET_FASTPATH(ci,
(UNLIKELY(ci->flag & VM_CALL_TAILCALL) ? vm_call_iseq_setup_tailcall : vm_call_iseq_setup_normal),
- (!IS_ARGS_SPLAT(ci) && !IS_ARGS_KEYWORD(ci) && !(ci->me->def->flag & NOEX_PROTECTED)));
+ (!IS_ARGS_SPLAT(ci) && !IS_ARGS_KEYWORD(ci) && !(ci->me->def->flags.visi == METHOD_VISI_PROTECTED)));
}
else {
ci->aux.opt_pc = setup_parameters_complex(th, iseq, ci, argv, arg_setup_method);
@@ -1659,7 +1659,7 @@ vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_info_t *ci)
RUBY_DTRACE_CMETHOD_ENTRY_HOOK(th, me->klass, me->called_id);
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->called_id, me->klass, Qnil);
- if (!(ci->me->def->flag & NOEX_PROTECTED) &&
+ if (!(ci->me->def->flag & METHOD_VISI_PROTECTED) &&
!(ci->flag & VM_CALL_ARGS_SPLAT) &&
!(ci->kw_arg != NULL)) {
CI_SET_FASTPATH(ci, vm_call_cfunc_latter, 1);
@@ -1740,16 +1740,12 @@ vm_call_bmethod(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci)
return vm_call_bmethod_body(th, ci, argv);
}
-static int
+static enum missing_reason
ci_missing_reason(const rb_call_info_t *ci)
{
- int stat = 0;
- if (ci->flag & VM_CALL_VCALL) {
- stat |= NOEX_VCALL;
- }
- if (ci->flag & VM_CALL_SUPER) {
- stat |= NOEX_SUPER;
- }
+ enum missing_reason stat = MISSING_NOENTRY;
+ if (ci->flag & VM_CALL_VCALL) stat |= MISSING_VCALL;
+ if (ci->flag & VM_CALL_SUPER) stat |= MISSING_SUPER;
return stat;
}
@@ -1915,7 +1911,7 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci)
start_method_dispatch:
if (ci->me != 0) {
- if ((ci->me->def->flag == 0)) {
+ if (ci->me->def->flags.visi == METHOD_VISI_PUBLIC && ci->me->def->flags.safe == 0) {
VALUE klass;
normal_method_dispatch:
@@ -2042,28 +2038,27 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci)
rb_bug("vm_call_method: unsupported method type (%d)", ci->me->def->type);
}
else {
- int noex_safe;
- if (!(ci->flag & VM_CALL_FCALL) && (ci->me->def->flag & NOEX_MASK) & NOEX_PRIVATE) {
- int stat = NOEX_PRIVATE;
+ int safe;
+ if (!(ci->flag & VM_CALL_FCALL) && (ci->me->def->flags.visi == METHOD_VISI_PRIVATE)) {
+ enum missing_reason stat = MISSING_PRIVATE;
+ bp();
+ if (ci->flag & VM_CALL_VCALL) stat |= MISSING_VCALL;
- if (ci->flag & VM_CALL_VCALL) {
- stat |= NOEX_VCALL;
- }
ci->aux.missing_reason = stat;
CI_SET_FASTPATH(ci, vm_call_method_missing, 1);
return vm_call_method_missing(th, cfp, ci);
}
- else if (!(ci->flag & VM_CALL_OPT_SEND) && (ci->me->def->flag & NOEX_MASK) & NOEX_PROTECTED) {
+ else if (!(ci->flag & VM_CALL_OPT_SEND) && (ci->me->def->flags.visi == METHOD_VISI_PROTECTED)) {
enable_fastpath = 0;
if (!rb_obj_is_kind_of(cfp->self, ci->defined_class)) {
- ci->aux.missing_reason = NOEX_PROTECTED;
+ ci->aux.missing_reason = MISSING_PROTECTED;
return vm_call_method_missing(th, cfp, ci);
}
else {
goto normal_method_dispatch;
}
}
- else if ((noex_safe = NOEX_SAFE(ci->me->def->flag)) > th->safe_level && (noex_safe > 2)) {
+ else if ((safe = ci->me->def->flags.safe) > th->safe_level && safe > 2) {
rb_raise(rb_eSecurityError, "calling insecure method: %"PRIsVALUE, rb_id2str(ci->mid));
}
else {
@@ -2216,7 +2211,7 @@ vm_search_super_method(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_inf
}
if (!ci->klass) {
/* bound instance method of module */
- ci->aux.missing_reason = NOEX_SUPER;
+ ci->aux.missing_reason = MISSING_SUPER;
CI_SET_FASTPATH(ci, vm_call_method_missing, 1);
return;
}
@@ -2475,9 +2470,19 @@ vm_defined(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_num_t op_type, VALUE
if (me) {
const rb_method_definition_t *def = me->def;
- if (!(def->flag & NOEX_PRIVATE) &&
- !((def->flag & NOEX_PROTECTED) && !rb_obj_is_kind_of(GET_SELF(), rb_class_real(klass)))) {
+
+ switch ((unsigned int)def->flags.visi) {
+ case METHOD_VISI_PRIVATE:
+ break;
+ case METHOD_VISI_PROTECTED:
+ if (!rb_obj_is_kind_of(GET_SELF(), rb_class_real(klass))) {
+ break;
+ }
+ case METHOD_VISI_PUBLIC:
expr_type = DEFINED_METHOD;
+ break;
+ default:
+ rb_bug("unreachable");
}
}
else {