diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-23 17:37:51 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-23 17:37:51 +0000 |
commit | 0f2fdc6978fb05e0149473a79d6083a1dd63e743 (patch) | |
tree | 86b8aed05bafca48afc80bf4304ab5fcdb33fa14 | |
parent | 140a9e7be3d0fb44b1266b6aece93310d9f41e88 (diff) | |
download | ruby-0f2fdc6978fb05e0149473a79d6083a1dd63e743.tar.gz |
* io.c (io_read): [ruby-dev:24952]
* configure.in, io.c: cancel [ ruby-Patches-1074 ].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | configure.in | 3 | ||||
-rw-r--r-- | io.c | 111 |
3 files changed, 55 insertions, 61 deletions
@@ -2,6 +2,8 @@ Wed Nov 24 01:01:31 2004 Yukihiro Matsumoto <matz@ruby-lang.org> * io.c (io_read): [ruby-dev:24952] + * configure.in, io.c: cancel [ ruby-Patches-1074 ]. + Tue Nov 23 08:09:50 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> * ext/tk/lib/tk/menu.rb: improve usability of TkOptionMenubutton diff --git a/configure.in b/configure.in index cff1e174e0..30444e6765 100644 --- a/configure.in +++ b/configure.in @@ -588,9 +588,6 @@ else AC_DEFINE(RSHIFT(x,y), (((x)<0) ? ~((~(x))>>y) : (x)>>y)) fi -AC_CHECK_HEADERS(stdio_ext.h) -AC_CHECK_FUNCS(__fpending) - AC_MSG_CHECKING(read count field in FILE structures) AC_CACHE_VAL(rb_cv_fcnt, [for fcnt in dnl @@ -127,9 +127,6 @@ static VALUE lineno = INT2FIX(0); # define READ_DATA_PENDING_COUNT(fp) ((fp)->_egptr - (fp)->_gptr) # define READ_DATA_PENDING_PTR(fp) ((fp)->_gptr) # endif -#elif defined(HAVE___FPENDING) -# define READ_DATA_PENDING(fp) (__fpending(fp) > 0) -# define READ_DATA_PENDING_COUNT(fp) (__fpending(fp)) #elif defined(FILE_COUNT) # define READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0) # define READ_DATA_PENDING_COUNT(fp) ((fp)->FILE_COUNT) @@ -590,8 +587,9 @@ rb_io_seek(io, offset, whence) OpenFile *fptr; off_t pos; + pos = NUM2OFFT(offset); GetOpenFile(io, fptr); - pos = io_seek(fptr, NUM2OFFT(offset), whence); + pos = io_seek(fptr, pos, whence); if (pos < 0) rb_sys_fail(fptr->path); clearerr(fptr->f); @@ -653,8 +651,9 @@ rb_io_set_pos(io, offset) OpenFile *fptr; off_t pos; + pos = NUM2OFFT(offset); GetOpenFile(io, fptr); - pos = io_seek(fptr, NUM2OFFT(offset), SEEK_SET); + pos = io_seek(fptr, pos, SEEK_SET); if (pos < 0) rb_sys_fail(fptr->path); clearerr(fptr->f); @@ -1034,7 +1033,6 @@ read_all(fptr, siz, str) str = rb_tainted_str_new(0, siz); } else { - StringValue(str); rb_str_resize(str, siz); } for (;;) { @@ -1124,9 +1122,6 @@ io_readpartial(argc, argv, io) rb_scan_args(argc, argv, "11", &length, &str); - GetOpenFile(io, fptr); - rb_io_check_readable(fptr); - if ((len = NUM2LONG(length)) < 0) { rb_raise(rb_eArgError, "negative length %ld given", len); } @@ -1141,6 +1136,9 @@ io_readpartial(argc, argv, io) } OBJ_TAINT(str); + GetOpenFile(io, fptr); + rb_io_check_readable(fptr); + if (len == 0) return str; @@ -1197,20 +1195,16 @@ io_read(argc, argv, io) rb_scan_args(argc, argv, "02", &length, &str); - if (!NIL_P(length)) { - len = NUM2LONG(length); - if (len < 0) { - rb_raise(rb_eArgError, "negative length %ld given", len); - } - } - - GetOpenFile(io, fptr); - rb_io_check_readable(fptr); - if (NIL_P(length)) { + GetOpenFile(io, fptr); + rb_io_check_readable(fptr); return read_all(fptr, remain_size(fptr), str); } - if (feof(fptr->f)) return Qnil; + len = NUM2LONG(length); + if (len < 0) { + rb_raise(rb_eArgError, "negative length %ld given", len); + } + if (NIL_P(str)) { str = rb_str_new(0, len); } @@ -1219,6 +1213,10 @@ io_read(argc, argv, io) rb_str_modify(str); rb_str_resize(str,len); } + + GetOpenFile(io, fptr); + rb_io_check_readable(fptr); + if (feof(fptr->f)) return Qnil; if (len == 0) return str; rb_str_locktmp(str); @@ -1414,12 +1412,13 @@ rscheck(rsptr, rslen, rs) } static VALUE -rb_io_getline(rs, fptr) - VALUE rs; - OpenFile *fptr; +rb_io_getline(rs, io) + VALUE rs, io; { VALUE str = Qnil; + OpenFile *fptr; + GetOpenFile(io, fptr); rb_io_check_readable(fptr); if (NIL_P(rs)) { str = read_all(fptr, 0, Qnil); @@ -1434,7 +1433,6 @@ rb_io_getline(rs, fptr) long rslen; int rspara = 0; - StringValue(rs); rslen = RSTRING(rs)->len; if (rslen == 0) { rsptr = "\n\n"; @@ -1517,9 +1515,9 @@ rb_io_gets_m(argc, argv, io) } else { rb_scan_args(argc, argv, "1", &rs); + if (!NIL_P(rs)) StringValue(rs); } - GetOpenFile(io, fptr); - str = rb_io_getline(rs, fptr); + str = rb_io_getline(rs, io); rb_lastline_set(str); return str; @@ -1661,10 +1659,10 @@ rb_io_readlines(argc, argv, io) } else { rb_scan_args(argc, argv, "1", &rs); + if (!NIL_P(rs)) StringValue(rs); } - GetOpenFile(io, fptr); ary = rb_ary_new(); - while (!NIL_P(line = rb_io_getline(rs, fptr))) { + while (!NIL_P(line = rb_io_getline(rs, io))) { rb_ary_push(ary, line); } return ary; @@ -1705,9 +1703,9 @@ rb_io_each_line(argc, argv, io) } else { rb_scan_args(argc, argv, "1", &rs); + if (!NIL_P(rs)) StringValue(rs); } - GetOpenFile(io, fptr); - while (!NIL_P(str = rb_io_getline(rs, fptr))) { + while (!NIL_P(str = rb_io_getline(rs, io))) { rb_yield(str); } return io; @@ -2170,7 +2168,7 @@ rb_io_sysseek(argc, argv, io) if (rb_scan_args(argc, argv, "11", &offset, &ptrname) == 2) { whence = NUM2INT(ptrname); } - + pos = NUM2OFFT(offset); GetOpenFile(io, fptr); if ((fptr->mode & FMODE_READABLE) && READ_DATA_BUFFERED(fptr->f)) { rb_raise(rb_eIOError, "sysseek for buffered IO"); @@ -2178,7 +2176,7 @@ rb_io_sysseek(argc, argv, io) if ((fptr->mode & FMODE_WRITABLE) && (fptr->mode & FMODE_WBUF)) { rb_warn("sysseek for buffered IO"); } - pos = lseek(fileno(fptr->f), NUM2OFFT(offset), whence); + pos = lseek(fileno(fptr->f), pos, whence); if (pos == -1) rb_sys_fail(fptr->path); clearerr(fptr->f); @@ -2255,12 +2253,7 @@ rb_io_sysread(argc, argv, io) rb_scan_args(argc, argv, "11", &len, &str); ilen = NUM2LONG(len); - GetOpenFile(io, fptr); - rb_io_check_readable(fptr); - if (READ_DATA_BUFFERED(fptr->f)) { - rb_raise(rb_eIOError, "sysread for buffered IO"); - } if (NIL_P(str)) { str = rb_str_new(0, ilen); } @@ -2271,6 +2264,12 @@ rb_io_sysread(argc, argv, io) } if (ilen == 0) return str; + GetOpenFile(io, fptr); + rb_io_check_readable(fptr); + + if (READ_DATA_BUFFERED(fptr->f)) { + rb_raise(rb_eIOError, "sysread for buffered IO"); + } n = fileno(fptr->f); rb_thread_wait_fd(fileno(fptr->f)); TRAP_BEG; @@ -3961,13 +3960,6 @@ rb_io_initialize(argc, argv, io) if (NIL_P(orig)) { fd = NUM2INT(fnum); } - else { - GetOpenFile(orig, ofp); - if (ofp->refcnt == LONG_MAX) { - VALUE s = rb_inspect(orig); - rb_raise(rb_eIOError, "too many shared IO for %s", StringValuePtr(s)); - } - } if (argc == 2) { if (FIXNUM_P(mode)) { flags = FIX2LONG(mode); @@ -3976,17 +3968,21 @@ rb_io_initialize(argc, argv, io) SafeStringValue(mode); flags = rb_io_mode_modenum(RSTRING(mode)->ptr); } - fmode = rb_io_modenum_flags(flags); } - else if (!ofp) { + else if (!NIL_P(orig)) { + GetOpenFile(orig, ofp); + if (ofp->refcnt == LONG_MAX) { + VALUE s = rb_inspect(orig); + rb_raise(rb_eIOError, "too many shared IO for %s", StringValuePtr(s)); + } #if defined(HAVE_FCNTL) && defined(F_GETFL) flags = fcntl(fd, F_GETFL); if (flags == -1) rb_sys_fail(0); #else flags = O_RDONLY; #endif - fmode = rb_io_modenum_flags(flags); } + fmode = rb_io_modenum_flags(flags); if (!ofp) { MakeOpenFile(io, fp); fp->mode = fmode; @@ -4276,16 +4272,15 @@ argf_getline(argc, argv) } else { VALUE rs; - OpenFile *fptr; if (argc == 0) { rs = rb_rs; } else { rb_scan_args(argc, argv, "1", &rs); + if (!NIL_P(rs)) StringValue(rs); } - GetOpenFile(current_file, fptr); - line = rb_io_getline(rs, fptr); + line = rb_io_getline(rs, current_file); } if (NIL_P(line) && next_p != -1) { argf_close(current_file); @@ -4981,7 +4976,6 @@ struct foreach_arg { int argc; VALUE sep; VALUE io; - OpenFile *fptr; }; static VALUE @@ -4990,7 +4984,7 @@ io_s_foreach(arg) { VALUE str; - while (!NIL_P(str = rb_io_getline(arg->sep, arg->fptr))) { + while (!NIL_P(str = rb_io_getline(arg->sep, arg->io))) { rb_yield(str); } return Qnil; @@ -5018,7 +5012,7 @@ rb_io_s_foreach(argc, argv) int argc; VALUE *argv; { - VALUE fname, io; + VALUE fname; OpenFile *fptr; struct foreach_arg arg; @@ -5027,12 +5021,13 @@ rb_io_s_foreach(argc, argv) if (argc == 1) { arg.sep = rb_default_rs; } - io = rb_io_open(RSTRING(fname)->ptr, "r"); - if (NIL_P(io)) return Qnil; - GetOpenFile(io, fptr); - arg.fptr = fptr; + else if (!NIL_P(arg.sep)) { + StringValue(arg.sep); + } + arg.io = rb_io_open(RSTRING(fname)->ptr, "r"); + if (NIL_P(arg.io)) return Qnil; - return rb_ensure(io_s_foreach, (VALUE)&arg, rb_io_close, io); + return rb_ensure(io_s_foreach, (VALUE)&arg, rb_io_close, arg.io); } static VALUE |