From a67f1a9534322914367d6eb17eb01badd87e7f79 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 27 Jun 2010 14:31:19 +0000 Subject: * include/ruby/io.h, io.c: reverted r21709. * ruby.c (load_file_internal): nothing to read if EOF reached while reading shebang. [ruby-core:30910] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'ruby.c') diff --git a/ruby.c b/ruby.c index 4dc0003e27..1a445ea6cd 100644 --- a/ruby.c +++ b/ruby.c @@ -1598,6 +1598,10 @@ load_file_internal(VALUE arg) else if (!NIL_P(c)) { rb_io_ungetbyte(f, c); } + else { + if (f != rb_stdin) rb_io_close(f); + f = Qnil; + } rb_vm_set_progname(rb_progname = opt->script_name); require_libraries(&opt->req_list); /* Why here? unnatural */ } @@ -1610,6 +1614,11 @@ load_file_internal(VALUE arg) else { enc = rb_usascii_encoding(); } + if (NIL_P(f)) { + f = rb_str_new(0, 0); + rb_enc_associate(f, enc); + return (VALUE)rb_parser_compile_string(parser, fname, f, line_start); + } rb_funcall(f, set_encoding, 2, rb_enc_from_encoding(enc), rb_str_new_cstr("-")); tree = rb_parser_compile_file(parser, fname, f, line_start); rb_funcall(f, set_encoding, 1, rb_parser_encoding(parser)); @@ -1619,9 +1628,6 @@ load_file_internal(VALUE arg) else if (f != rb_stdin) { rb_io_close(f); } - else { - rb_io_ungetbyte(f, Qnil); - } return (VALUE)tree; } -- cgit v1.2.3