ruby-changes:49822
From: nobu <ko1@a...>
Date: Fri, 19 Jan 2018 12:09:29 +0900 (JST)
Subject: [ruby-changes:49822] nobu:r61940 (trunk): vm_insnhelper.c: fix many keyword arguments
nobu 2018-01-19 12:09:24 +0900 (Fri, 19 Jan 2018) New Revision: 61940 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61940 Log: vm_insnhelper.c: fix many keyword arguments * vm_insnhelper.c (vm_check_keyword): if the index exceeds the width of unspecified bits, that argument is specified. `unspecified_bits` still be a fixnum if the actual arguments do not exceed the limit, regardless the formal parameters size. [ruby-core:84921] [Bug #14373] Modified files: trunk/test/ruby/test_keyword.rb trunk/vm_args.c trunk/vm_insnhelper.c Index: vm_args.c =================================================================== --- vm_args.c (revision 61939) +++ vm_args.c (revision 61940) @@ -392,6 +392,8 @@ args_setup_kw_parameters_lookup(const ID https://github.com/ruby/ruby/blob/trunk/vm_args.c#L392 return FALSE; } +#define KW_SPECIFIED_BITS_MAX 32 /* TODO: 32 -> Fixnum's max bits */ + static void args_setup_kw_parameters(rb_execution_context_t *const ec, const rb_iseq_t *const iseq, VALUE *const passed_values, const int passed_keyword_len, const VALUE *const passed_keywords, @@ -427,7 +429,7 @@ args_setup_kw_parameters(rb_execution_co https://github.com/ruby/ruby/blob/trunk/vm_args.c#L429 if (default_values[di] == Qundef) { locals[i] = Qnil; - if (LIKELY(i < 32)) { /* TODO: 32 -> Fixnum's max bits */ + if (LIKELY(i < KW_SPECIFIED_BITS_MAX)) { unspecified_bits |= 0x01 << di; } else { @@ -436,7 +438,7 @@ args_setup_kw_parameters(rb_execution_co https://github.com/ruby/ruby/blob/trunk/vm_args.c#L438 int j; unspecified_bits_value = rb_hash_new(); - for (j=0; j<32; j++) { + for (j=0; j<KW_SPECIFIED_BITS_MAX; j++) { if (unspecified_bits & (0x01 << j)) { rb_hash_aset(unspecified_bits_value, INT2FIX(j), Qtrue); } Index: test/ruby/test_keyword.rb =================================================================== --- test/ruby/test_keyword.rb (revision 61939) +++ test/ruby/test_keyword.rb (revision 61940) @@ -681,12 +681,13 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L681 def many_kwargs(a0: '', a1: '', a2: '', a3: '', a4: '', a5: '', a6: '', a7: '', b0: '', b1: '', b2: '', b3: '', b4: '', b5: '', b6: '', b7: '', c0: '', c1: '', c2: '', c3: '', c4: '', c5: '', c6: '', c7: '', - d0: '', d1: '', d2: '', d3: '', d4: '', d5: '', d6: '', d7: '') + d0: '', d1: '', d2: '', d3: '', d4: '', d5: '', d6: '', d7: '', + e0: '') [a0, a1, a2, a3, a4, a5, a6, a7, b0, b1, b2, b3, b4, b5, b6, b7, c0, c1, c2, c3, c4, c5, c6, c7, d0, d1, d2, d3, d4, d5, d6, d7, - ] + e0] end def test_many_kwargs @@ -726,5 +727,7 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L727 assert_equal(:ok, many_kwargs(d5: :ok)[i], "#{i}: d5"); i+=1 assert_equal(:ok, many_kwargs(d6: :ok)[i], "#{i}: d6"); i+=1 assert_equal(:ok, many_kwargs(d7: :ok)[i], "#{i}: d7"); i+=1 + + assert_equal(:ok, many_kwargs(e0: :ok)[i], "#{i}: e0"); i+=1 end end Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 61939) +++ vm_insnhelper.c (revision 61940) @@ -3029,7 +3029,8 @@ vm_check_keyword(lindex_t bits, lindex_t https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3029 if (FIXNUM_P(kw_bits)) { int b = FIX2INT(kw_bits); - if (b & (0x01 << idx)) return Qfalse; + if ((idx < KW_SPECIFIED_BITS_MAX) && (b & (0x01 << idx))) + return Qfalse; } else { VM_ASSERT(RB_TYPE_P(kw_bits, T_HASH)); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/