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

ruby-changes:40006

From: shugo <ko1@a...>
Date: Fri, 9 Oct 2015 12:58:56 +0900 (JST)
Subject: [ruby-changes:40006] shugo:r52087 (trunk): * compile.c (iseq_compile_each): Dynamic string literals (e.g.,

shugo	2015-10-09 12:58:34 +0900 (Fri, 09 Oct 2015)

  New Revision: 52087

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

  Log:
    * compile.c (iseq_compile_each): Dynamic string literals (e.g.,
      "#{x}") should not be frozen because they don't literally
      represent strings.
      https://twitter.com/shugomaeda/status/651937650027401216
      https://twitter.com/yukihiro_matz/status/651942882312482817
      https://twitter.com/yukihiro_matz/status/651980835181096960

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/test/ruby/test_iseq.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52086)
+++ ChangeLog	(revision 52087)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Oct  9 12:52:08 2015  Shugo Maeda  <shugo@r...>
+
+	* compile.c (iseq_compile_each): Dynamic string literals (e.g.,
+	  "#{x}") should not be frozen because they don't literally
+	  represent strings.
+	  https://twitter.com/shugomaeda/status/651937650027401216
+	  https://twitter.com/yukihiro_matz/status/651942882312482817
+	  https://twitter.com/yukihiro_matz/status/651980835181096960
+
 Fri Oct  9 06:52:49 2015  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* benchmark/prepare_require.rb: skip file creation if it already
Index: compile.c
===================================================================
--- compile.c	(revision 52086)
+++ compile.c	(revision 52087)
@@ -5059,11 +5059,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5059
 	if (poped) {
 	    ADD_INSN(ret, line, pop);
 	}
-	else {
-	    if (iseq->compile_data->option->frozen_string_literal) {
-		ADD_SEND (ret, line, idFreeze, INT2FIX(0));
-	    }
-	}
 	break;
       }
       case NODE_XSTR:{
Index: test/ruby/test_iseq.rb
===================================================================
--- test/ruby/test_iseq.rb	(revision 52086)
+++ test/ruby/test_iseq.rb	(revision 52087)
@@ -166,12 +166,13 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L166
     $f = 'f'
     line = __LINE__ + 2
     code = <<-'EOS'
-    ['foo', 'foo', "#{$f}foo"]
+    ['foo', 'foo', "#{$f}foo", "#{'foo'}"]
     EOS
-    s1, s2, s3 = RubyVM::InstructionSequence.compile(code, __FILE__, __FILE__, line, {frozen_string_literal: true}).eval
-    assert(s1.frozen?)
-    assert(s2.frozen?)
-    assert(s3.frozen?)
-    assert(s1.object_id == s2.object_id)
+    s1, s2, s3, s4 = RubyVM::InstructionSequence.compile(code, __FILE__, __FILE__, line, {frozen_string_literal: true}).eval
+    assert_equal(true, s1.frozen?)
+    assert_equal(true, s2.frozen?)
+    assert_equal(false, s3.frozen?)
+    assert_equal(true, s4.frozen?)
+    assert_equal(s2.object_id, s2.object_id)
   end
 end

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

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