From 13bcc1f5b0f7f377bedbdd8bf0464225836ebd13 Mon Sep 17 00:00:00 2001 From: ko1 Date: Wed, 16 Dec 2015 18:20:29 +0000 Subject: * vm_insnhelper.c (vm_call_method_each_type): should not set fastpath with keyword arguments for VM_METHOD_TYPE_ATTRSET type methods. Normally, we can not use keyword arguments for this kind of methods, (obj.foo = 1), but we can set alias names for them. [Bug #11657] * test/ruby/test_keyword.rb: add a test for this fix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ test/ruby/test_keyword.rb | 20 ++++++++++++++++++++ vm_insnhelper.c | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f88c77cbd0..bef6a757a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Thu Dec 17 03:15:25 2015 Koichi Sasada + + * vm_insnhelper.c (vm_call_method_each_type): should not set fastpath + with keyword arguments for VM_METHOD_TYPE_ATTRSET type methods. + + Normally, we can not use keyword arguments for this kind of methods, + (obj.foo = 1), but we can set alias names for them. + [Bug #11657] + + * test/ruby/test_keyword.rb: add a test for this fix. + Wed Dec 16 20:32:43 2015 CHIKANAGA Tomoyuki * ext/fiddle/handle.c: check tainted string arguments. diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index f6923248ff..b8ca84c27e 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -577,4 +577,24 @@ class TestKeywordArguments < Test::Unit::TestCase h = method_for_test_to_hash_call_during_setup_complex_parameters k1: "foo", k2: "bar", sym => "baz" assert_equal ["foo", "bar", {sym => "baz"}], h, '[Bug #11027]' end + + class AttrSetTest + attr_accessor :foo + alias set_foo :foo= + end + + def test_attr_set_method_cache + obj = AttrSetTest.new + h = {a: 1, b: 2} + 2.times{ + obj.foo = 1 + assert_equal(1, obj.foo) + obj.set_foo 2 + assert_equal(2, obj.foo) + obj.set_foo(x: 1, y: 2) + assert_equal({x: 1, y: 2}, obj.foo) + obj.set_foo(x: 1, y: 2, **h) + assert_equal({x: 1, y: 2, **h}, obj.foo) + } + end end diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 3f06b31732..44e7183eb4 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2096,7 +2096,7 @@ vm_call_method_each_type(rb_thread_t *th, rb_control_frame_t *cfp, struct rb_cal CALLER_SETUP_ARG(cfp, calling, ci); rb_check_arity(calling->argc, 1, 1); cc->aux.index = 0; - CI_SET_FASTPATH(cc, vm_call_attrset, !(ci->flag & VM_CALL_ARGS_SPLAT)); + CI_SET_FASTPATH(cc, vm_call_attrset, !((ci->flag & VM_CALL_ARGS_SPLAT) || (ci->flag & VM_CALL_KWARG))); return vm_call_attrset(th, cfp, calling, ci, cc); case VM_METHOD_TYPE_IVAR: -- cgit v1.2.3