summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-27 14:31:19 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-27 14:31:19 +0000
commit1f1937111dba69ee8deb6b0c23b11abddaeadbdc (patch)
tree00da341d418b285a679c9f81bc06f638a7b4f410 /ruby.c
parentc69fda5e2a56c49c5e8cc66a35474f1aa69ca34d (diff)
* 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/branches/ruby_1_9_2@28451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/ruby.c b/ruby.c
index 8cb65ba3e6..e7c73b352f 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1593,6 +1593,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 */
}
@@ -1605,6 +1609,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));
@@ -1614,9 +1623,6 @@ load_file_internal(VALUE arg)
else if (f != rb_stdin) {
rb_io_close(f);
}
- else {
- rb_io_ungetbyte(f, Qnil);
- }
return (VALUE)tree;
}