* 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
This commit is contained in:
parent
140a9e7be3
commit
0f2fdc6978
@ -2,6 +2,8 @@ Wed Nov 24 01:01:31 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
|||||||
|
|
||||||
* io.c (io_read): [ruby-dev:24952]
|
* 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>
|
Tue Nov 23 08:09:50 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
* ext/tk/lib/tk/menu.rb: improve usability of TkOptionMenubutton
|
* ext/tk/lib/tk/menu.rb: improve usability of TkOptionMenubutton
|
||||||
|
@ -588,9 +588,6 @@ else
|
|||||||
AC_DEFINE(RSHIFT(x,y), (((x)<0) ? ~((~(x))>>y) : (x)>>y))
|
AC_DEFINE(RSHIFT(x,y), (((x)<0) ? ~((~(x))>>y) : (x)>>y))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_CHECK_HEADERS(stdio_ext.h)
|
|
||||||
AC_CHECK_FUNCS(__fpending)
|
|
||||||
|
|
||||||
AC_MSG_CHECKING(read count field in FILE structures)
|
AC_MSG_CHECKING(read count field in FILE structures)
|
||||||
AC_CACHE_VAL(rb_cv_fcnt,
|
AC_CACHE_VAL(rb_cv_fcnt,
|
||||||
[for fcnt in dnl
|
[for fcnt in dnl
|
||||||
|
107
io.c
107
io.c
@ -127,9 +127,6 @@ static VALUE lineno = INT2FIX(0);
|
|||||||
# define READ_DATA_PENDING_COUNT(fp) ((fp)->_egptr - (fp)->_gptr)
|
# define READ_DATA_PENDING_COUNT(fp) ((fp)->_egptr - (fp)->_gptr)
|
||||||
# define READ_DATA_PENDING_PTR(fp) ((fp)->_gptr)
|
# define READ_DATA_PENDING_PTR(fp) ((fp)->_gptr)
|
||||||
# endif
|
# 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)
|
#elif defined(FILE_COUNT)
|
||||||
# define READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
|
# define READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
|
||||||
# define READ_DATA_PENDING_COUNT(fp) ((fp)->FILE_COUNT)
|
# define READ_DATA_PENDING_COUNT(fp) ((fp)->FILE_COUNT)
|
||||||
@ -590,8 +587,9 @@ rb_io_seek(io, offset, whence)
|
|||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
off_t pos;
|
off_t pos;
|
||||||
|
|
||||||
|
pos = NUM2OFFT(offset);
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
pos = io_seek(fptr, NUM2OFFT(offset), whence);
|
pos = io_seek(fptr, pos, whence);
|
||||||
if (pos < 0) rb_sys_fail(fptr->path);
|
if (pos < 0) rb_sys_fail(fptr->path);
|
||||||
clearerr(fptr->f);
|
clearerr(fptr->f);
|
||||||
|
|
||||||
@ -653,8 +651,9 @@ rb_io_set_pos(io, offset)
|
|||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
off_t pos;
|
off_t pos;
|
||||||
|
|
||||||
|
pos = NUM2OFFT(offset);
|
||||||
GetOpenFile(io, fptr);
|
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);
|
if (pos < 0) rb_sys_fail(fptr->path);
|
||||||
clearerr(fptr->f);
|
clearerr(fptr->f);
|
||||||
|
|
||||||
@ -1034,7 +1033,6 @@ read_all(fptr, siz, str)
|
|||||||
str = rb_tainted_str_new(0, siz);
|
str = rb_tainted_str_new(0, siz);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
StringValue(str);
|
|
||||||
rb_str_resize(str, siz);
|
rb_str_resize(str, siz);
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -1124,9 +1122,6 @@ io_readpartial(argc, argv, io)
|
|||||||
|
|
||||||
rb_scan_args(argc, argv, "11", &length, &str);
|
rb_scan_args(argc, argv, "11", &length, &str);
|
||||||
|
|
||||||
GetOpenFile(io, fptr);
|
|
||||||
rb_io_check_readable(fptr);
|
|
||||||
|
|
||||||
if ((len = NUM2LONG(length)) < 0) {
|
if ((len = NUM2LONG(length)) < 0) {
|
||||||
rb_raise(rb_eArgError, "negative length %ld given", len);
|
rb_raise(rb_eArgError, "negative length %ld given", len);
|
||||||
}
|
}
|
||||||
@ -1141,6 +1136,9 @@ io_readpartial(argc, argv, io)
|
|||||||
}
|
}
|
||||||
OBJ_TAINT(str);
|
OBJ_TAINT(str);
|
||||||
|
|
||||||
|
GetOpenFile(io, fptr);
|
||||||
|
rb_io_check_readable(fptr);
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return str;
|
return str;
|
||||||
|
|
||||||
@ -1197,20 +1195,16 @@ io_read(argc, argv, io)
|
|||||||
|
|
||||||
rb_scan_args(argc, argv, "02", &length, &str);
|
rb_scan_args(argc, argv, "02", &length, &str);
|
||||||
|
|
||||||
if (!NIL_P(length)) {
|
if (NIL_P(length)) {
|
||||||
|
GetOpenFile(io, fptr);
|
||||||
|
rb_io_check_readable(fptr);
|
||||||
|
return read_all(fptr, remain_size(fptr), str);
|
||||||
|
}
|
||||||
len = NUM2LONG(length);
|
len = NUM2LONG(length);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
rb_raise(rb_eArgError, "negative length %ld given", len);
|
rb_raise(rb_eArgError, "negative length %ld given", len);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GetOpenFile(io, fptr);
|
|
||||||
rb_io_check_readable(fptr);
|
|
||||||
|
|
||||||
if (NIL_P(length)) {
|
|
||||||
return read_all(fptr, remain_size(fptr), str);
|
|
||||||
}
|
|
||||||
if (feof(fptr->f)) return Qnil;
|
|
||||||
if (NIL_P(str)) {
|
if (NIL_P(str)) {
|
||||||
str = rb_str_new(0, len);
|
str = rb_str_new(0, len);
|
||||||
}
|
}
|
||||||
@ -1219,6 +1213,10 @@ io_read(argc, argv, io)
|
|||||||
rb_str_modify(str);
|
rb_str_modify(str);
|
||||||
rb_str_resize(str,len);
|
rb_str_resize(str,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetOpenFile(io, fptr);
|
||||||
|
rb_io_check_readable(fptr);
|
||||||
|
if (feof(fptr->f)) return Qnil;
|
||||||
if (len == 0) return str;
|
if (len == 0) return str;
|
||||||
|
|
||||||
rb_str_locktmp(str);
|
rb_str_locktmp(str);
|
||||||
@ -1414,12 +1412,13 @@ rscheck(rsptr, rslen, rs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_io_getline(rs, fptr)
|
rb_io_getline(rs, io)
|
||||||
VALUE rs;
|
VALUE rs, io;
|
||||||
OpenFile *fptr;
|
|
||||||
{
|
{
|
||||||
VALUE str = Qnil;
|
VALUE str = Qnil;
|
||||||
|
OpenFile *fptr;
|
||||||
|
|
||||||
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_readable(fptr);
|
rb_io_check_readable(fptr);
|
||||||
if (NIL_P(rs)) {
|
if (NIL_P(rs)) {
|
||||||
str = read_all(fptr, 0, Qnil);
|
str = read_all(fptr, 0, Qnil);
|
||||||
@ -1434,7 +1433,6 @@ rb_io_getline(rs, fptr)
|
|||||||
long rslen;
|
long rslen;
|
||||||
int rspara = 0;
|
int rspara = 0;
|
||||||
|
|
||||||
StringValue(rs);
|
|
||||||
rslen = RSTRING(rs)->len;
|
rslen = RSTRING(rs)->len;
|
||||||
if (rslen == 0) {
|
if (rslen == 0) {
|
||||||
rsptr = "\n\n";
|
rsptr = "\n\n";
|
||||||
@ -1517,9 +1515,9 @@ rb_io_gets_m(argc, argv, io)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_scan_args(argc, argv, "1", &rs);
|
rb_scan_args(argc, argv, "1", &rs);
|
||||||
|
if (!NIL_P(rs)) StringValue(rs);
|
||||||
}
|
}
|
||||||
GetOpenFile(io, fptr);
|
str = rb_io_getline(rs, io);
|
||||||
str = rb_io_getline(rs, fptr);
|
|
||||||
rb_lastline_set(str);
|
rb_lastline_set(str);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
@ -1661,10 +1659,10 @@ rb_io_readlines(argc, argv, io)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_scan_args(argc, argv, "1", &rs);
|
rb_scan_args(argc, argv, "1", &rs);
|
||||||
|
if (!NIL_P(rs)) StringValue(rs);
|
||||||
}
|
}
|
||||||
GetOpenFile(io, fptr);
|
|
||||||
ary = rb_ary_new();
|
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);
|
rb_ary_push(ary, line);
|
||||||
}
|
}
|
||||||
return ary;
|
return ary;
|
||||||
@ -1705,9 +1703,9 @@ rb_io_each_line(argc, argv, io)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_scan_args(argc, argv, "1", &rs);
|
rb_scan_args(argc, argv, "1", &rs);
|
||||||
|
if (!NIL_P(rs)) StringValue(rs);
|
||||||
}
|
}
|
||||||
GetOpenFile(io, fptr);
|
while (!NIL_P(str = rb_io_getline(rs, io))) {
|
||||||
while (!NIL_P(str = rb_io_getline(rs, fptr))) {
|
|
||||||
rb_yield(str);
|
rb_yield(str);
|
||||||
}
|
}
|
||||||
return io;
|
return io;
|
||||||
@ -2170,7 +2168,7 @@ rb_io_sysseek(argc, argv, io)
|
|||||||
if (rb_scan_args(argc, argv, "11", &offset, &ptrname) == 2) {
|
if (rb_scan_args(argc, argv, "11", &offset, &ptrname) == 2) {
|
||||||
whence = NUM2INT(ptrname);
|
whence = NUM2INT(ptrname);
|
||||||
}
|
}
|
||||||
|
pos = NUM2OFFT(offset);
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
if ((fptr->mode & FMODE_READABLE) && READ_DATA_BUFFERED(fptr->f)) {
|
if ((fptr->mode & FMODE_READABLE) && READ_DATA_BUFFERED(fptr->f)) {
|
||||||
rb_raise(rb_eIOError, "sysseek for buffered IO");
|
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)) {
|
if ((fptr->mode & FMODE_WRITABLE) && (fptr->mode & FMODE_WBUF)) {
|
||||||
rb_warn("sysseek for buffered IO");
|
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);
|
if (pos == -1) rb_sys_fail(fptr->path);
|
||||||
clearerr(fptr->f);
|
clearerr(fptr->f);
|
||||||
|
|
||||||
@ -2255,12 +2253,7 @@ rb_io_sysread(argc, argv, io)
|
|||||||
|
|
||||||
rb_scan_args(argc, argv, "11", &len, &str);
|
rb_scan_args(argc, argv, "11", &len, &str);
|
||||||
ilen = NUM2LONG(len);
|
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)) {
|
if (NIL_P(str)) {
|
||||||
str = rb_str_new(0, ilen);
|
str = rb_str_new(0, ilen);
|
||||||
}
|
}
|
||||||
@ -2271,6 +2264,12 @@ rb_io_sysread(argc, argv, io)
|
|||||||
}
|
}
|
||||||
if (ilen == 0) return str;
|
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);
|
n = fileno(fptr->f);
|
||||||
rb_thread_wait_fd(fileno(fptr->f));
|
rb_thread_wait_fd(fileno(fptr->f));
|
||||||
TRAP_BEG;
|
TRAP_BEG;
|
||||||
@ -3961,13 +3960,6 @@ rb_io_initialize(argc, argv, io)
|
|||||||
if (NIL_P(orig)) {
|
if (NIL_P(orig)) {
|
||||||
fd = NUM2INT(fnum);
|
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 (argc == 2) {
|
||||||
if (FIXNUM_P(mode)) {
|
if (FIXNUM_P(mode)) {
|
||||||
flags = FIX2LONG(mode);
|
flags = FIX2LONG(mode);
|
||||||
@ -3976,17 +3968,21 @@ rb_io_initialize(argc, argv, io)
|
|||||||
SafeStringValue(mode);
|
SafeStringValue(mode);
|
||||||
flags = rb_io_mode_modenum(RSTRING(mode)->ptr);
|
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)
|
#if defined(HAVE_FCNTL) && defined(F_GETFL)
|
||||||
flags = fcntl(fd, F_GETFL);
|
flags = fcntl(fd, F_GETFL);
|
||||||
if (flags == -1) rb_sys_fail(0);
|
if (flags == -1) rb_sys_fail(0);
|
||||||
#else
|
#else
|
||||||
flags = O_RDONLY;
|
flags = O_RDONLY;
|
||||||
#endif
|
#endif
|
||||||
fmode = rb_io_modenum_flags(flags);
|
|
||||||
}
|
}
|
||||||
|
fmode = rb_io_modenum_flags(flags);
|
||||||
if (!ofp) {
|
if (!ofp) {
|
||||||
MakeOpenFile(io, fp);
|
MakeOpenFile(io, fp);
|
||||||
fp->mode = fmode;
|
fp->mode = fmode;
|
||||||
@ -4276,16 +4272,15 @@ argf_getline(argc, argv)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE rs;
|
VALUE rs;
|
||||||
OpenFile *fptr;
|
|
||||||
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
rs = rb_rs;
|
rs = rb_rs;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_scan_args(argc, argv, "1", &rs);
|
rb_scan_args(argc, argv, "1", &rs);
|
||||||
|
if (!NIL_P(rs)) StringValue(rs);
|
||||||
}
|
}
|
||||||
GetOpenFile(current_file, fptr);
|
line = rb_io_getline(rs, current_file);
|
||||||
line = rb_io_getline(rs, fptr);
|
|
||||||
}
|
}
|
||||||
if (NIL_P(line) && next_p != -1) {
|
if (NIL_P(line) && next_p != -1) {
|
||||||
argf_close(current_file);
|
argf_close(current_file);
|
||||||
@ -4981,7 +4976,6 @@ struct foreach_arg {
|
|||||||
int argc;
|
int argc;
|
||||||
VALUE sep;
|
VALUE sep;
|
||||||
VALUE io;
|
VALUE io;
|
||||||
OpenFile *fptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -4990,7 +4984,7 @@ io_s_foreach(arg)
|
|||||||
{
|
{
|
||||||
VALUE str;
|
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);
|
rb_yield(str);
|
||||||
}
|
}
|
||||||
return Qnil;
|
return Qnil;
|
||||||
@ -5018,7 +5012,7 @@ rb_io_s_foreach(argc, argv)
|
|||||||
int argc;
|
int argc;
|
||||||
VALUE *argv;
|
VALUE *argv;
|
||||||
{
|
{
|
||||||
VALUE fname, io;
|
VALUE fname;
|
||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
struct foreach_arg arg;
|
struct foreach_arg arg;
|
||||||
|
|
||||||
@ -5027,12 +5021,13 @@ rb_io_s_foreach(argc, argv)
|
|||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
arg.sep = rb_default_rs;
|
arg.sep = rb_default_rs;
|
||||||
}
|
}
|
||||||
io = rb_io_open(RSTRING(fname)->ptr, "r");
|
else if (!NIL_P(arg.sep)) {
|
||||||
if (NIL_P(io)) return Qnil;
|
StringValue(arg.sep);
|
||||||
GetOpenFile(io, fptr);
|
}
|
||||||
arg.fptr = fptr;
|
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
|
static VALUE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user