mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
d9edd4ca87
commit
a67f1a9534
5 changed files with 43 additions and 22 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Sun Jun 27 23:31:17 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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]
|
||||||
|
|
||||||
Sun Jun 27 13:25:07 2010 Tanaka Akira <akr@fsij.org>
|
Sun Jun 27 13:25:07 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* io.c (simple_sendfile): don't try to send data more than SSIZE_MAX
|
* io.c (simple_sendfile): don't try to send data more than SSIZE_MAX
|
||||||
|
|
|
@ -92,7 +92,6 @@ typedef struct rb_io_t {
|
||||||
#define FMODE_WSPLIT_INITIALIZED 0x00000400
|
#define FMODE_WSPLIT_INITIALIZED 0x00000400
|
||||||
#define FMODE_TRUNC 0x00000800
|
#define FMODE_TRUNC 0x00000800
|
||||||
#define FMODE_TEXTMODE 0x00001000
|
#define FMODE_TEXTMODE 0x00001000
|
||||||
#define FMODE_EOF 0x00002000
|
|
||||||
/* #define FMODE_PREP 0x00010000 */
|
/* #define FMODE_PREP 0x00010000 */
|
||||||
#define FMODE_SETENC_BY_BOM 0x00100000
|
#define FMODE_SETENC_BY_BOM 0x00100000
|
||||||
|
|
||||||
|
|
21
io.c
21
io.c
|
@ -398,9 +398,7 @@ flush_before_seek(rb_io_t *fptr)
|
||||||
return fptr;
|
return fptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define io_set_eof(fptr) (void)(((fptr)->mode & FMODE_TTY) && ((fptr)->mode |= FMODE_EOF))
|
#define io_seek(fptr, ofs, whence) (errno = 0, lseek(flush_before_seek(fptr)->fd, ofs, whence))
|
||||||
#define io_unset_eof(fptr) (fptr->mode &= ~FMODE_EOF)
|
|
||||||
#define io_seek(fptr, ofs, whence) (errno = 0, io_unset_eof(fptr), lseek(flush_before_seek(fptr)->fd, ofs, whence))
|
|
||||||
#define io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)
|
#define io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)
|
||||||
|
|
||||||
#ifndef SEEK_CUR
|
#ifndef SEEK_CUR
|
||||||
|
@ -1203,9 +1201,6 @@ io_fillbuf(rb_io_t *fptr)
|
||||||
{
|
{
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
|
|
||||||
if (fptr->mode & FMODE_EOF) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (fptr->rbuf == NULL) {
|
if (fptr->rbuf == NULL) {
|
||||||
fptr->rbuf_off = 0;
|
fptr->rbuf_off = 0;
|
||||||
fptr->rbuf_len = 0;
|
fptr->rbuf_len = 0;
|
||||||
|
@ -1224,10 +1219,8 @@ io_fillbuf(rb_io_t *fptr)
|
||||||
}
|
}
|
||||||
fptr->rbuf_off = 0;
|
fptr->rbuf_off = 0;
|
||||||
fptr->rbuf_len = (int)r; /* r should be <= rbuf_capa */
|
fptr->rbuf_len = (int)r; /* r should be <= rbuf_capa */
|
||||||
if (r == 0) {
|
if (r == 0)
|
||||||
io_set_eof(fptr);
|
|
||||||
return -1; /* EOF */
|
return -1; /* EOF */
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1533,10 +1526,7 @@ io_fread(VALUE str, long offset, rb_io_t *fptr)
|
||||||
while (n > 0) {
|
while (n > 0) {
|
||||||
again:
|
again:
|
||||||
c = rb_read_internal(fptr->fd, RSTRING_PTR(str)+offset, n);
|
c = rb_read_internal(fptr->fd, RSTRING_PTR(str)+offset, n);
|
||||||
if (c == 0) {
|
if (c == 0) break;
|
||||||
io_set_eof(fptr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (c < 0) {
|
if (c < 0) {
|
||||||
if (rb_io_wait_readable(fptr->fd))
|
if (rb_io_wait_readable(fptr->fd))
|
||||||
goto again;
|
goto again;
|
||||||
|
@ -1870,9 +1860,6 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
|
||||||
rb_mod_sys_fail(rb_mWaitReadable, "read would block");
|
rb_mod_sys_fail(rb_mWaitReadable, "read would block");
|
||||||
rb_sys_fail_path(fptr->pathv);
|
rb_sys_fail_path(fptr->pathv);
|
||||||
}
|
}
|
||||||
else if (n == 0) {
|
|
||||||
io_set_eof(fptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rb_str_resize(str, n);
|
rb_str_resize(str, n);
|
||||||
|
|
||||||
|
@ -3154,7 +3141,6 @@ rb_io_ungetbyte(VALUE io, VALUE b)
|
||||||
|
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_byte_readable(fptr);
|
rb_io_check_byte_readable(fptr);
|
||||||
io_unset_eof(fptr);
|
|
||||||
if (NIL_P(b)) return Qnil;
|
if (NIL_P(b)) return Qnil;
|
||||||
if (FIXNUM_P(b)) {
|
if (FIXNUM_P(b)) {
|
||||||
char cc = FIX2INT(b);
|
char cc = FIX2INT(b);
|
||||||
|
@ -3191,7 +3177,6 @@ rb_io_ungetc(VALUE io, VALUE c)
|
||||||
|
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_char_readable(fptr);
|
rb_io_check_char_readable(fptr);
|
||||||
io_unset_eof(fptr);
|
|
||||||
if (NIL_P(c)) return Qnil;
|
if (NIL_P(c)) return Qnil;
|
||||||
if (FIXNUM_P(c)) {
|
if (FIXNUM_P(c)) {
|
||||||
int cc = FIX2INT(c);
|
int cc = FIX2INT(c);
|
||||||
|
|
12
ruby.c
12
ruby.c
|
@ -1598,6 +1598,10 @@ load_file_internal(VALUE arg)
|
||||||
else if (!NIL_P(c)) {
|
else if (!NIL_P(c)) {
|
||||||
rb_io_ungetbyte(f, 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);
|
rb_vm_set_progname(rb_progname = opt->script_name);
|
||||||
require_libraries(&opt->req_list); /* Why here? unnatural */
|
require_libraries(&opt->req_list); /* Why here? unnatural */
|
||||||
}
|
}
|
||||||
|
@ -1610,6 +1614,11 @@ load_file_internal(VALUE arg)
|
||||||
else {
|
else {
|
||||||
enc = rb_usascii_encoding();
|
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("-"));
|
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);
|
tree = rb_parser_compile_file(parser, fname, f, line_start);
|
||||||
rb_funcall(f, set_encoding, 1, rb_parser_encoding(parser));
|
rb_funcall(f, set_encoding, 1, rb_parser_encoding(parser));
|
||||||
|
@ -1619,9 +1628,6 @@ load_file_internal(VALUE arg)
|
||||||
else if (f != rb_stdin) {
|
else if (f != rb_stdin) {
|
||||||
rb_io_close(f);
|
rb_io_close(f);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
rb_io_ungetbyte(f, Qnil);
|
|
||||||
}
|
|
||||||
return (VALUE)tree;
|
return (VALUE)tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -421,4 +421,28 @@ class TestRubyOptions < Test::Unit::TestCase
|
||||||
assert_in_out_err(["-we", "a=1"], "", [], ["-e:1: warning: assigned but unused variable - a"], feature3446)
|
assert_in_out_err(["-we", "a=1"], "", [], ["-e:1: warning: assigned but unused variable - a"], feature3446)
|
||||||
assert_in_out_err(["-we", "1.times do\n a=1\nend"], "", [], ["-e:2: warning: assigned but unused variable - a"], feature3446)
|
assert_in_out_err(["-we", "1.times do\n a=1\nend"], "", [], ["-e:2: warning: assigned but unused variable - a"], feature3446)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_script_from_stdin
|
||||||
|
begin
|
||||||
|
require 'pty'
|
||||||
|
require 'io/console'
|
||||||
|
rescue LoadError
|
||||||
|
return
|
||||||
|
end
|
||||||
|
require 'timeout'
|
||||||
|
result = nil
|
||||||
|
PTY.spawn(EnvUtil.rubybin) do |s, m|
|
||||||
|
m.print("\C-d")
|
||||||
|
assert_nothing_raised('[ruby-dev:37798]') do
|
||||||
|
Timeout.timeout(3) {s.read}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
PTY.spawn(EnvUtil.rubybin) do |s, m|
|
||||||
|
m.print("$stdin.read; p $stdin.gets\n\C-d")
|
||||||
|
m.print("abc\n\C-d")
|
||||||
|
m.print("zzz\n")
|
||||||
|
result = s.read
|
||||||
|
end
|
||||||
|
assert_match(/zzz\r\n"zzz\\n"\r\n\z/, result, '[ruby-core:30910]')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue