mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
vm.c: respect redefinition of Proc#call
* vm.c (vm_redefinition_check_method_type): hoist out method definition type to check redefinition. * vm.c (rb_vm_check_redefinition_opt_method): should check optimized method too. * vm.c (vm_init_redefined_flag): check Proc#call. * vm_insnhelper.c (vm_call_opt_block_call): search proper method if redefined. [Bug #14335] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c818e364df
commit
0948eb62e6
3 changed files with 34 additions and 4 deletions
|
@ -1390,4 +1390,22 @@ class TestProc < Test::Unit::TestCase
|
|||
e.each {}
|
||||
EOS
|
||||
end
|
||||
|
||||
def test_prepended_call
|
||||
assert_in_out_err([], "#{<<~"begin;"}\n#{<<~'end;'}", ["call"])
|
||||
begin;
|
||||
Proc.prepend Module.new {def call() puts "call"; super; end}
|
||||
def m(&blk) blk.call; end
|
||||
m {}
|
||||
end;
|
||||
end
|
||||
|
||||
def test_refined_call
|
||||
assert_in_out_err([], "#{<<~"begin;"}\n#{<<~'end;'}", ["call"])
|
||||
begin;
|
||||
using Module.new {refine(Proc) {def call() puts "call"; super; end}}
|
||||
def m(&blk) blk.call; end
|
||||
m {}
|
||||
end;
|
||||
end
|
||||
end
|
||||
|
|
19
vm.c
19
vm.c
|
@ -1500,6 +1500,18 @@ vm_redefinition_check_flag(VALUE klass)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
vm_redefinition_check_method_type(const rb_method_definition_t *def)
|
||||
{
|
||||
switch (def->type) {
|
||||
case VM_METHOD_TYPE_CFUNC:
|
||||
case VM_METHOD_TYPE_OPTIMIZED:
|
||||
return TRUE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
rb_vm_check_redefinition_opt_method(const rb_method_entry_t *me, VALUE klass)
|
||||
{
|
||||
|
@ -1507,7 +1519,7 @@ rb_vm_check_redefinition_opt_method(const rb_method_entry_t *me, VALUE klass)
|
|||
if (RB_TYPE_P(klass, T_ICLASS) && FL_TEST(klass, RICLASS_IS_ORIGIN)) {
|
||||
klass = RBASIC_CLASS(klass);
|
||||
}
|
||||
if (me->def->type == VM_METHOD_TYPE_CFUNC) {
|
||||
if (vm_redefinition_check_method_type(me->def)) {
|
||||
if (st_lookup(vm_opt_method_table, (st_data_t)me, &bop)) {
|
||||
int flag = vm_redefinition_check_flag(klass);
|
||||
|
||||
|
@ -1540,9 +1552,7 @@ add_opt_method(VALUE klass, ID mid, VALUE bop)
|
|||
{
|
||||
const rb_method_entry_t *me = rb_method_entry_at(klass, mid);
|
||||
|
||||
if (me &&
|
||||
(me->def->type == VM_METHOD_TYPE_CFUNC ||
|
||||
me->def->type == VM_METHOD_TYPE_OPTIMIZED)) {
|
||||
if (me && vm_redefinition_check_method_type(me->def)) {
|
||||
st_insert(vm_opt_method_table, (st_data_t)me, (st_data_t)bop);
|
||||
}
|
||||
else {
|
||||
|
@ -1584,6 +1594,7 @@ vm_init_redefined_flag(void)
|
|||
OP(UMinus, UMINUS), (C(String));
|
||||
OP(Max, MAX), (C(Array));
|
||||
OP(Min, MIN), (C(Array));
|
||||
OP(Call, CALL), (C(Proc));
|
||||
#undef C
|
||||
#undef OP
|
||||
}
|
||||
|
|
|
@ -2086,6 +2086,7 @@ vm_call_opt_block_call(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
|
|||
}
|
||||
else {
|
||||
calling->recv = rb_vm_bh_to_procval(ec, block_handler);
|
||||
vm_search_method(ci, cc, calling->recv);
|
||||
return vm_call_general(ec, reg_cfp, calling, ci, cc);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue