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

ruby-changes:56857

From: nagachika <ko1@a...>
Date: Wed, 7 Aug 2019 22:05:26 +0900 (JST)
Subject: [ruby-changes:56857] nagachika: a93a2f88d2 (ruby_2_6): merge revision(s) 5931857281ce45c1c277aa86d1588119ab00a955,76e2370f132f83c16c9de39a0a9356579f364527: [Backport #16041]

https://git.ruby-lang.org/ruby.git/commit/?id=a93a2f88d2

From a93a2f88d277b14818d0240ef48f2f2311933d2e Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Wed, 7 Aug 2019 13:05:00 +0000
Subject: merge revision(s)
 5931857281ce45c1c277aa86d1588119ab00a955,76e2370f132f83c16c9de39a0a9356579f364527:
 [Backport #16041]

	Fix dangling path name from fstring

	* parse.y (yycompile): make sure in advance that the `__FILE__`
	  object shares a fstring, to get rid of dangling path name.
	  Fixed up 53e9908d8afc7f03109b0aafd1698ab35f512b05.  [Bug #16041]

	* vm_eval.c (eval_make_iseq): ditto.

	Fix dangling path name from fstring

	* load.c (rb_require_internal): make sure in advance that the path
	  to be loaded shares a fstring, to get rid of dangling path name.
	  Fixed up 5931857281ce45c1c277aa86d1588119ab00a955.  [Bug #16041]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

diff --git a/load.c b/load.c
index 544357d..57a9c9c 100644
--- a/load.c
+++ b/load.c
@@ -1016,7 +1016,7 @@ rb_require_internal(VALUE fname, int safe) https://github.com/ruby/ruby/blob/trunk/load.c#L1016
 	RUBY_DTRACE_HOOK(FIND_REQUIRE_RETURN, RSTRING_PTR(fname));
 
 	if (found) {
-	    if (!path || !(ftptr = load_lock(RSTRING_PTR(path)))) {
+	    if (!path || !(path = rb_fstring(path), ftptr = load_lock(RSTRING_PTR(path)))) {
 		result = 0;
 	    }
 	    else if (!*ftptr) {
diff --git a/parse.y b/parse.y
index 473ae0e..b81dbbc 100644
--- a/parse.y
+++ b/parse.y
@@ -4941,7 +4941,7 @@ yycompile(VALUE vparser, struct parser_params *p, VALUE fname, int line) https://github.com/ruby/ruby/blob/trunk/parse.y#L4941
 	p->ruby_sourcefile = "(none)";
     }
     else {
-	p->ruby_sourcefile_string = rb_str_new_frozen(fname);
+	p->ruby_sourcefile_string = rb_fstring(fname);
 	p->ruby_sourcefile = StringValueCStr(fname);
     }
     p->ruby_sourceline = line - 1;
@@ -8760,7 +8760,7 @@ gettable(struct parser_params *p, ID id, const YYLTYPE *loc) https://github.com/ruby/ruby/blob/trunk/parse.y#L8760
 	    if (NIL_P(file))
 		file = rb_str_new(0, 0);
 	    else
-		file = rb_str_dup(rb_fstring(file));
+		file = rb_str_dup(file);
 	    node = NEW_STR(add_mark_object(p, file), loc);
 	}
 	return node;
diff --git a/test/ruby/test_eval.rb b/test/ruby/test_eval.rb
index 8900b4f..9cb69dd 100644
--- a/test/ruby/test_eval.rb
+++ b/test/ruby/test_eval.rb
@@ -497,6 +497,17 @@ class TestEval < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_eval.rb#L497
     }, '[Bug #10368]'
   end
 
+  def test_gced_eval_location
+    Dir.mktmpdir do |d|
+      File.write("#{d}/2.rb", "")
+      File.write("#{d}/1.rb", "require_relative '2'\n""__FILE__\n")
+      file = "1.rb"
+      path = File.expand_path(file, d)
+      assert_equal(path, eval(File.read(path), nil, File.expand_path(file, d)))
+      assert_equal(path, eval(File.read(path), nil, File.expand_path(file, d)))
+    end
+  end
+
   def orphan_proc
     proc {eval("return :ng")}
   end
diff --git a/version.h b/version.h
index d5cc057..3af9fe5 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #define RUBY_VERSION "2.6.3"
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 86
+#define RUBY_PATCHLEVEL 87
 
 #define RUBY_RELEASE_YEAR 2019
 #define RUBY_RELEASE_MONTH 8
diff --git a/vm_eval.c b/vm_eval.c
index 0e7047a..e759197 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1266,6 +1266,7 @@ eval_make_iseq(VALUE src, VALUE fname, int line, const rb_binding_t *bind, https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1266
     }
 
     if (fname != Qundef) {
+        if (!NIL_P(fname)) fname = rb_fstring(fname);
 	realpath = fname;
     }
     else if (bind) {
@@ -1275,7 +1276,7 @@ eval_make_iseq(VALUE src, VALUE fname, int line, const rb_binding_t *bind, https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1276
 	rb_parser_warn_location(parser, TRUE);
     }
     else {
-	fname = rb_usascii_str_new_cstr("(eval)");
+	fname = rb_fstring_lit("(eval)");
     }
 
     rb_parser_set_context(parser, base_block, FALSE);
-- 
cgit v0.10.2


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

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