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

ruby-changes:35566

From: nobu <ko1@a...>
Date: Sat, 20 Sep 2014 10:23:08 +0900 (JST)
Subject: [ruby-changes:35566] nobu:r47648 (trunk): compile.c: store IDs as Symbols

nobu	2014-09-20 10:23:02 +0900 (Sat, 20 Sep 2014)

  New Revision: 47648

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

  Log:
    compile.c: store IDs as Symbols
    
    * compile.c (iseq_set_arguments): store local variable IDs in
      temporary list as Symbols.  previously these are stored as
      Fixnums to prevent from GC, but IDs of dynamic symbols can
      exceed Fixnum range and cause RangeError at inverting from
      Fixnum.  [ruby-dev:48564] [Bug #10266]

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/test/ruby/test_keyword.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47647)
+++ ChangeLog	(revision 47648)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Sep 20 10:23:00 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* compile.c (iseq_set_arguments): store local variable IDs in
+	  temporary list as Symbols.  previously these are stored as
+	  Fixnums to prevent from GC, but IDs of dynamic symbols can
+	  exceed Fixnum range and cause RangeError at inverting from
+	  Fixnum.  [ruby-dev:48564] [Bug #10266]
+
 Sat Sep 20 10:02:51 2014  Tanaka Akira  <akr@f...>
 
 	* ext/openssl/lib/openssl/x509.rb (OpenSSL::X509::Name#pretty_print):
Index: compile.c
===================================================================
--- compile.c	(revision 47647)
+++ compile.c	(revision 47648)
@@ -1237,7 +1237,7 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L1237
 		    if (!required) required = rb_ary_tmp_new(1);
 		    list = required;
 		}
-		rb_ary_push(list, INT2FIX(node->nd_body->nd_vid));
+		rb_ary_push(list, ID2SYM(node->nd_body->nd_vid));
 		COMPILE_POPED(optargs, "kwarg", node); /* nd_type(node) == NODE_KW_ARG */
 		node = node->nd_next;
 		i += 1;
@@ -1251,7 +1251,7 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L1251
 		keywords = required;
 	    }
 	    for (j = 0; j < i; j++) {
-		iseq->arg_keyword_table[j] = FIX2INT(RARRAY_AREF(keywords, j));
+		iseq->arg_keyword_table[j] = SYM2ID(RARRAY_AREF(keywords, j));
 	    }
 	    ADD_INSN(optargs, nd_line(args->kw_args), pop);
 	}
Index: test/ruby/test_keyword.rb
===================================================================
--- test/ruby/test_keyword.rb	(revision 47647)
+++ test/ruby/test_keyword.rb	(revision 47648)
@@ -491,4 +491,13 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L491
       tap { prc.call }
     }, bug8964
   end
+
+  def test_dynamic_symbol_keyword
+    bug10266 = '[ruby-dev:48564] [Bug #10266]'
+    assert_separately(['-', bug10266], <<-'end;') #    do
+      bug = ARGV.shift
+      "hoge".to_sym
+      assert_nothing_raised(bug) {eval("def a(hoge:); end")}
+    end;
+  end
 end

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

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