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

ruby-changes:46446

From: nobu <ko1@a...>
Date: Thu, 4 May 2017 15:54:17 +0900 (JST)
Subject: [ruby-changes:46446] nobu:r58561 (trunk): parse.y: make shared string modifiable

nobu	2017-05-04 15:54:11 +0900 (Thu, 04 May 2017)

  New Revision: 58561

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

  Log:
    parse.y: make shared string modifiable
    
    * parse.y (dedent_string): ensure that the string is modifiable,
      not to set the length of shared string.
      [ruby-core:80987] [Bug #13540]

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_parse.rb
Index: test/ruby/test_parse.rb
===================================================================
--- test/ruby/test_parse.rb	(revision 58560)
+++ test/ruby/test_parse.rb	(revision 58561)
@@ -988,6 +988,16 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L988
     assert_equal(-100, e.backtrace_locations.first.lineno, bug)
   end
 
+  def test_file_in_indented_heredoc
+    name = '[ruby-core:80987] [Bug #13540]' # long enough to be shared
+    assert_equal(name+"\n", eval("#{<<-"begin;"}\n#{<<-'end;'}", nil, name))
+    begin;
+      <<~HEREDOC
+        #{__FILE__}
+      HEREDOC
+    end;
+  end
+
 =begin
   def test_past_scope_variable
     assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
Index: parse.y
===================================================================
--- parse.y	(revision 58560)
+++ parse.y	(revision 58561)
@@ -6392,6 +6392,11 @@ dedent_string(VALUE string, int width) https://github.com/ruby/ruby/blob/trunk/parse.y#L6392
 	    break;
 	}
     }
+    if (!i) return 0;
+    rb_str_modify(string);
+    str = RSTRING_PTR(string);
+    if (RSTRING_LEN(string) != len)
+	rb_fatal("literal string changed: %+"PRIsVALUE, string);
     MEMMOVE(str, str + i, char, len - i);
     rb_str_set_len(string, len - i);
     return i;
@@ -6448,7 +6453,6 @@ parser_dedent_string(VALUE self, VALUE i https://github.com/ruby/ruby/blob/trunk/parse.y#L6453
 
     StringValue(input);
     wid = NUM2UINT(width);
-    rb_str_modify(input);
     col = dedent_string(input, wid);
     return INT2NUM(col);
 }

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

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