1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ruby.c (load_file): preserves $.. [ruby-dev:36937]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-10-27 06:58:28 +00:00
parent 782f3bd3f9
commit 0a20a506e1
2 changed files with 35 additions and 4 deletions

View file

@ -1,4 +1,6 @@
Mon Oct 27 15:55:04 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
Mon Oct 27 15:58:25 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (load_file): preserves $.. [ruby-dev:36937]
* io.c (argf_init): initial value of $. should be 0.
see [ruby-dev:36937].

35
ruby.c
View file

@ -1203,10 +1203,22 @@ process_options(VALUE arg)
return iseq;
}
static NODE *
load_file(VALUE parser, const char *fname, int script, struct cmdline_options *opt)
struct load_file_arg {
VALUE parser;
const char *fname;
int script;
struct cmdline_options *opt;
};
static VALUE
load_file_internal(VALUE arg)
{
extern VALUE rb_stdin;
struct load_file_arg *argp = (struct load_file_arg *)arg;
VALUE parser = argp->parser;
const char *fname = argp->fname;
int script = argp->script;
struct cmdline_options *opt = argp->opt;
VALUE f;
int line_start = 1;
NODE *tree = 0;
@ -1353,7 +1365,24 @@ load_file(VALUE parser, const char *fname, int script, struct cmdline_options *o
else if (f != rb_stdin) {
rb_io_close(f);
}
return tree;
return (VALUE)tree;
}
static VALUE
restore_lineno(VALUE lineno)
{
return rb_gv_set("$.", lineno);
}
static NODE *
load_file(VALUE parser, const char *fname, int script, struct cmdline_options *opt)
{
struct load_file_arg arg;
arg.parser = parser;
arg.fname = fname;
arg.script = script;
arg.opt = opt;
return (NODE *)rb_ensure(load_file_internal, (VALUE)&arg, restore_lineno, rb_gv_get("$."));
}
void *