summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-09 13:39:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-09 13:39:36 +0000
commit4bf84ede2013a69dba2b89080211e9aa59a533d5 (patch)
treec364eb949afc18837c800a1e636b5fe7967bb3f8 /parse.y
parent49c7c8ed85cfeaae98fbfb1828424e1e5bb9b0dc (diff)
Get rid of setting SCRIPT_LINES__ by AST.parse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65647 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y21
1 files changed, 17 insertions, 4 deletions
diff --git a/parse.y b/parse.y
index aed392822e..71392ea00c 100644
--- a/parse.y
+++ b/parse.y
@@ -4873,7 +4873,7 @@ yycompile0(VALUE arg)
struct parser_params *p = (struct parser_params *)arg;
VALUE cov = Qfalse;
- if (!compile_for_eval && rb_safe_level() == 0) {
+ if (!compile_for_eval && rb_safe_level() == 0 && !NIL_P(p->ruby_sourcefile_string)) {
p->debug_lines = debug_lines(p->ruby_sourcefile_string);
if (p->debug_lines && p->ruby_sourceline > 0) {
VALUE str = STR_NEW0();
@@ -4933,8 +4933,14 @@ static rb_ast_t *
yycompile(VALUE vparser, struct parser_params *p, VALUE fname, int line)
{
rb_ast_t *ast;
- p->ruby_sourcefile_string = rb_str_new_frozen(fname);
- p->ruby_sourcefile = StringValueCStr(fname);
+ if (NIL_P(fname)) {
+ p->ruby_sourcefile_string = Qnil;
+ p->ruby_sourcefile = "(none)";
+ }
+ else {
+ p->ruby_sourcefile_string = rb_str_new_frozen(fname);
+ p->ruby_sourcefile = StringValueCStr(fname);
+ }
p->ruby_sourceline = line - 1;
p->ast = ast = rb_ast_new();
@@ -8716,7 +8722,14 @@ gettable(struct parser_params *p, ID id, const YYLTYPE *loc)
return NEW_FALSE(loc);
case keyword__FILE__:
WARN_LOCATION("__FILE__");
- node = NEW_STR(add_mark_object(p, rb_str_dup(p->ruby_sourcefile_string)), loc);
+ {
+ VALUE file = p->ruby_sourcefile_string;
+ if (NIL_P(file))
+ file = rb_str_new(0, 0);
+ else
+ file = rb_str_dup(file);
+ node = NEW_STR(add_mark_object(p, file), loc);
+ }
return node;
case keyword__LINE__:
WARN_LOCATION("__LINE__");