ruby-changes:8434
From: nobu <ko1@a...>
Date: Mon, 27 Oct 2008 15:58:46 +0900 (JST)
Subject: [ruby-changes:8434] Ruby:r19965 (trunk): * ruby.c (load_file): preserves $..
nobu 2008-10-27 15:58:28 +0900 (Mon, 27 Oct 2008) New Revision: 19965 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19965 Log: * ruby.c (load_file): preserves $.. [ruby-dev:36937] Modified files: trunk/ChangeLog trunk/ruby.c Index: ChangeLog =================================================================== --- ChangeLog (revision 19964) +++ ChangeLog (revision 19965) @@ -1,5 +1,7 @@ -Mon Oct 27 15:55:04 2008 Nobuyoshi Nakada <nobu@r...> +Mon Oct 27 15:58:25 2008 Nobuyoshi Nakada <nobu@r...> + * ruby.c (load_file): preserves $.. [ruby-dev:36937] + * io.c (argf_init): initial value of $. should be 0. see [ruby-dev:36937]. Index: ruby.c =================================================================== --- ruby.c (revision 19964) +++ ruby.c (revision 19965) @@ -1203,10 +1203,22 @@ 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,9 +1365,26 @@ 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 * rb_load_file(const char *fname) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/