зеркало из https://github.com/github/ruby.git
Extract hook macro for attributes
This commit is contained in:
Родитель
162ad65fdd
Коммит
70624ae43d
26
vm_eval.c
26
vm_eval.c
|
@ -190,16 +190,9 @@ vm_call0_body(rb_execution_context_t *ec, struct rb_calling_info *calling, const
|
|||
}
|
||||
|
||||
rb_check_arity(calling->argc, 1, 1);
|
||||
if (UNLIKELY(ruby_vm_event_flags & (RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN))) {
|
||||
EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, calling->recv,
|
||||
vm_cc_cme(cc)->def->original_id, vm_ci_mid(ci), vm_cc_cme(cc)->owner, Qundef);
|
||||
ret = rb_ivar_set(calling->recv, vm_cc_cme(cc)->def->body.attr.id, argv[0]);
|
||||
EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, calling->recv,
|
||||
vm_cc_cme(cc)->def->original_id, vm_ci_mid(ci), vm_cc_cme(cc)->owner, ret);
|
||||
}
|
||||
else {
|
||||
ret = rb_ivar_set(calling->recv, vm_cc_cme(cc)->def->body.attr.id, argv[0]);
|
||||
}
|
||||
VM_CALL_METHOD_ATTR(ret,
|
||||
rb_ivar_set(calling->recv, vm_cc_cme(cc)->def->body.attr.id, argv[0]),
|
||||
(void)0);
|
||||
goto success;
|
||||
case VM_METHOD_TYPE_IVAR:
|
||||
if (calling->kw_splat &&
|
||||
|
@ -210,16 +203,9 @@ vm_call0_body(rb_execution_context_t *ec, struct rb_calling_info *calling, const
|
|||
}
|
||||
|
||||
rb_check_arity(calling->argc, 0, 0);
|
||||
if (UNLIKELY(ruby_vm_event_flags & (RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN))) {
|
||||
EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, calling->recv,
|
||||
vm_cc_cme(cc)->def->original_id, vm_ci_mid(ci), vm_cc_cme(cc)->owner, Qundef);
|
||||
ret = rb_attr_get(calling->recv, vm_cc_cme(cc)->def->body.attr.id);
|
||||
EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, calling->recv,
|
||||
vm_cc_cme(cc)->def->original_id, vm_ci_mid(ci), vm_cc_cme(cc)->owner, ret);
|
||||
}
|
||||
else {
|
||||
ret = rb_attr_get(calling->recv, vm_cc_cme(cc)->def->body.attr.id);
|
||||
}
|
||||
VM_CALL_METHOD_ATTR(ret,
|
||||
rb_attr_get(calling->recv, vm_cc_cme(cc)->def->body.attr.id),
|
||||
(void)0);
|
||||
goto success;
|
||||
case VM_METHOD_TYPE_BMETHOD:
|
||||
ret = vm_call_bmethod_body(ec, calling, argv);
|
||||
|
|
|
@ -3468,11 +3468,25 @@ vm_call_refined(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_c
|
|||
}
|
||||
}
|
||||
|
||||
#define VM_CALL_METHOD_ATTR(var, func, nohook) \
|
||||
if (UNLIKELY(ruby_vm_event_flags & (RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN))) { \
|
||||
EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, calling->recv, vm_cc_cme(cc)->def->original_id, \
|
||||
vm_ci_mid(ci), vm_cc_cme(cc)->owner, Qundef); \
|
||||
var = func; \
|
||||
EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, calling->recv, vm_cc_cme(cc)->def->original_id, \
|
||||
vm_ci_mid(ci), vm_cc_cme(cc)->owner, (var)); \
|
||||
} \
|
||||
else { \
|
||||
nohook; \
|
||||
var = func; \
|
||||
}
|
||||
|
||||
static VALUE
|
||||
vm_call_method_each_type(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_calling_info *calling)
|
||||
{
|
||||
const struct rb_callinfo *ci = calling->ci;
|
||||
const struct rb_callcache *cc = calling->cc;
|
||||
VALUE v;
|
||||
|
||||
switch (vm_cc_cme(cc)->def->type) {
|
||||
case VM_METHOD_TYPE_ISEQ:
|
||||
|
@ -3490,40 +3504,22 @@ vm_call_method_each_type(rb_execution_context_t *ec, rb_control_frame_t *cfp, st
|
|||
|
||||
rb_check_arity(calling->argc, 1, 1);
|
||||
vm_cc_attr_index_set(cc, 0);
|
||||
if (UNLIKELY(ruby_vm_event_flags & (RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN))) {
|
||||
const struct rb_callinfo *ci = calling->ci;
|
||||
VALUE v;
|
||||
EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, calling->recv, vm_cc_cme(cc)->def->original_id,
|
||||
vm_ci_mid(ci), vm_cc_cme(cc)->owner, Qundef);
|
||||
v = vm_call_attrset(ec, cfp, calling);
|
||||
EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, calling->recv, vm_cc_cme(cc)->def->original_id,
|
||||
vm_ci_mid(ci), vm_cc_cme(cc)->owner, v);
|
||||
const unsigned int aset_mask = (VM_CALL_ARGS_SPLAT | VM_CALL_KW_SPLAT | VM_CALL_KWARG);
|
||||
VM_CALL_METHOD_ATTR(v,
|
||||
vm_call_attrset(ec, cfp, calling),
|
||||
CC_SET_FASTPATH(cc, vm_call_attrset, !(vm_ci_flag(ci) & aset_mask)));
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
CC_SET_FASTPATH(cc, vm_call_attrset, !(vm_ci_flag(ci) & (VM_CALL_ARGS_SPLAT | VM_CALL_KW_SPLAT | VM_CALL_KWARG)));
|
||||
return vm_call_attrset(ec, cfp, calling);
|
||||
}
|
||||
|
||||
case VM_METHOD_TYPE_IVAR:
|
||||
CALLER_SETUP_ARG(cfp, calling, ci);
|
||||
CALLER_REMOVE_EMPTY_KW_SPLAT(cfp, calling, ci);
|
||||
rb_check_arity(calling->argc, 0, 0);
|
||||
vm_cc_attr_index_set(cc, 0);
|
||||
if (UNLIKELY(ruby_vm_event_flags & (RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN))) {
|
||||
const struct rb_callinfo *ci = calling->ci;
|
||||
VALUE v;
|
||||
EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, calling->recv, vm_cc_cme(cc)->def->original_id,
|
||||
vm_ci_mid(ci), vm_cc_cme(cc)->owner, Qundef);
|
||||
v = vm_call_ivar(ec, cfp, calling);
|
||||
EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, calling->recv, vm_cc_cme(cc)->def->original_id,
|
||||
vm_ci_mid(ci), vm_cc_cme(cc)->owner, v);
|
||||
const unsigned int ivar_mask = (VM_CALL_ARGS_SPLAT | VM_CALL_KW_SPLAT);
|
||||
VM_CALL_METHOD_ATTR(v,
|
||||
vm_call_ivar(ec, cfp, calling),
|
||||
CC_SET_FASTPATH(cc, vm_call_ivar, !(vm_ci_flag(ci) & ivar_mask)));
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
CC_SET_FASTPATH(cc, vm_call_ivar, !(vm_ci_flag(ci) & (VM_CALL_ARGS_SPLAT | VM_CALL_KW_SPLAT)));
|
||||
return vm_call_ivar(ec, cfp, calling);
|
||||
}
|
||||
|
||||
case VM_METHOD_TYPE_MISSING:
|
||||
vm_cc_method_missing_reason_set(cc, 0);
|
||||
|
|
Загрузка…
Ссылка в новой задаче