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

ruby.c: defining DATA

* ruby.c (load_file_internal): define DATA here instead of ensure
  func.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-01-31 12:55:00 +00:00
parent 3408e3b460
commit c7c1f371a4

38
ruby.c
View file

@ -1763,7 +1763,6 @@ load_file_internal(VALUE argp_v)
ID set_encoding; ID set_encoding;
int xflag = argp->xflag; int xflag = argp->xflag;
argp->script = 0;
CONST_ID(set_encoding, "set_encoding"); CONST_ID(set_encoding, "set_encoding");
if (script) { if (script) {
VALUE c = 1; /* something not nil */ VALUE c = 1; /* something not nil */
@ -1840,8 +1839,7 @@ load_file_internal(VALUE argp_v)
rb_io_ungetbyte(f, c); rb_io_ungetbyte(f, c);
} }
else { else {
if (f != rb_stdin) rb_io_close(f); argp->f = f = Qnil;
f = Qnil;
} }
if (!(opt->dump & ~DUMP_BIT(version_v))) { if (!(opt->dump & ~DUMP_BIT(version_v))) {
ruby_set_script_name(opt->script_name); ruby_set_script_name(opt->script_name);
@ -1865,7 +1863,22 @@ load_file_internal(VALUE argp_v)
rb_funcall(f, set_encoding, 2, rb_enc_from_encoding(enc), rb_str_new_cstr("-")); rb_funcall(f, set_encoding, 2, rb_enc_from_encoding(enc), rb_str_new_cstr("-"));
tree = rb_parser_compile_file_path(parser, orig_fname, f, line_start); tree = rb_parser_compile_file_path(parser, orig_fname, f, line_start);
rb_funcall(f, set_encoding, 1, rb_parser_encoding(parser)); rb_funcall(f, set_encoding, 1, rb_parser_encoding(parser));
if (script && rb_parser_end_seen_p(parser)) argp->script = script; if (script && rb_parser_end_seen_p(parser)) {
/*
* DATA is a File that contains the data section of the executed file.
* To create a data section use <tt>__END__</tt>:
*
* $ cat t.rb
* puts DATA.gets
* __END__
* hello world!
*
* $ ruby t.rb
* hello world!
*/
rb_define_global_const("DATA", f);
argp->f = Qnil;
}
return (VALUE)tree; return (VALUE)tree;
} }
@ -1951,22 +1964,7 @@ restore_load_file(VALUE arg)
struct load_file_arg *argp = (struct load_file_arg *)arg; struct load_file_arg *argp = (struct load_file_arg *)arg;
VALUE f = argp->f; VALUE f = argp->f;
if (argp->script) { if (!NIL_P(f) && f != rb_stdin) {
/*
* DATA is a File that contains the data section of the executed file.
* To create a data section use <tt>__END__</tt>:
*
* $ cat t.rb
* puts DATA.gets
* __END__
* hello world!
*
* $ ruby t.rb
* hello world!
*/
rb_define_global_const("DATA", f);
}
else if (f != rb_stdin) {
rb_io_close(f); rb_io_close(f);
} }
return Qnil; return Qnil;