[前][次][番号順一覧][スレッド一覧]

ruby-changes:41089

From: ko1 <ko1@a...>
Date: Thu, 17 Dec 2015 03:20:46 +0900 (JST)
Subject: [ruby-changes:41089] ko1:r53164 (trunk): * vm_insnhelper.c (vm_call_method_each_type): should not set fastpath

ko1	2015-12-17 03:20:29 +0900 (Thu, 17 Dec 2015)

  New Revision: 53164

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53164

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_keyword.rb
    trunk/vm_insnhelper.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53163)
+++ ChangeLog	(revision 53164)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Dec 17 03:15:25 2015  Koichi Sasada  <ko1@a...>
+
+	* 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  <nagachika@r...>
 
 	* ext/fiddle/handle.c: check tainted string arguments.
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 53163)
+++ vm_insnhelper.c	(revision 53164)
@@ -2096,7 +2096,7 @@ vm_call_method_each_type(rb_thread_t *th https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2096
 	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:
Index: test/ruby/test_keyword.rb
===================================================================
--- test/ruby/test_keyword.rb	(revision 53163)
+++ test/ruby/test_keyword.rb	(revision 53164)
@@ -577,4 +577,24 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L577
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]