From 3083ad7b83486e217ce7c112ed4610f3d4ba3702 Mon Sep 17 00:00:00 2001 From: ko1 Date: Mon, 15 Oct 2012 21:35:29 +0000 Subject: * vm_insnhelper.c (vm_call_method): disable CI_SET_FASTPATH() if this method call needs splat argument because cahced functions (vm_call_attrset, vm_call_ivar, vm_call_cfunc_fast_(unary|binary)) do not check an arity. * bootstraptest/test_method.rb: add a test to check an above issue. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ bootstraptest/test_method.rb | 20 ++++++++++++++++++++ vm_insnhelper.c | 8 ++++---- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2fe1fe1419..2144d209a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Tue Oct 16 06:29:18 2012 Koichi Sasada + + * vm_insnhelper.c (vm_call_method): disable CI_SET_FASTPATH() if + this method call needs splat argument because cahced functions + (vm_call_attrset, vm_call_ivar, vm_call_cfunc_fast_(unary|binary)) + do not check an arity. + + * bootstraptest/test_method.rb: add a test to check an above issue. + Tue Oct 16 06:15:44 2012 Koichi Sasada * method.h: introduce new method type VM_METHOD_TYPE_CFUNC_FAST. diff --git a/bootstraptest/test_method.rb b/bootstraptest/test_method.rb index 2baf33539d..d6b8c0ea24 100644 --- a/bootstraptest/test_method.rb +++ b/bootstraptest/test_method.rb @@ -1184,3 +1184,23 @@ assert_equal 'ok', %q{ 'ok' }, '[ruby-core:30534]' +# should not cache when splat +assert_equal 'ok', %q{ + class C + attr_reader :a + def initialize + @a = 1 + end + end + + def m *args + C.new.a(*args) + end + + m() + begin + m(1) + rescue ArgumentError + 'ok' + end +} diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 78c6c85a26..239f67f3dd 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1523,13 +1523,13 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci) } case VM_METHOD_TYPE_ATTRSET:{ rb_check_arity(ci->argc, 0, 1); - CI_SET_FASTPATH(ci, vm_call_attrset, enable_fastpath); + CI_SET_FASTPATH(ci, vm_call_attrset, enable_fastpath && !(ci->flag & VM_CALL_ARGS_SPLAT)); val = vm_call_attrset(th, cfp, ci); break; } case VM_METHOD_TYPE_IVAR:{ rb_check_arity(ci->argc, 0, 0); - CI_SET_FASTPATH(ci, vm_call_ivar, enable_fastpath); + CI_SET_FASTPATH(ci, vm_call_ivar, enable_fastpath && !(ci->flag & VM_CALL_ARGS_SPLAT)); val = vm_call_ivar(th, cfp, ci); break; } @@ -1577,12 +1577,12 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci) switch (ci->me->def->body.cfunc.argc) { case 0: rb_check_arity(ci->argc, 0, 0); - CI_SET_FASTPATH(ci, vm_call_cfunc_fast_unary, enable_fastpath); + CI_SET_FASTPATH(ci, vm_call_cfunc_fast_unary, enable_fastpath && !(ci->flag & VM_CALL_ARGS_SPLAT)); val = vm_call_cfunc_fast_unary(th, cfp, ci); break; case 1: rb_check_arity(ci->argc, 0, 1); - CI_SET_FASTPATH(ci, vm_call_cfunc_fast_binary, enable_fastpath); + CI_SET_FASTPATH(ci, vm_call_cfunc_fast_binary, enable_fastpath && !(ci->flag & VM_CALL_ARGS_SPLAT)); val = vm_call_cfunc_fast_binary(th, cfp, ci); break; default: -- cgit v1.2.3