* include/ruby/io.h (rb_io_buffer_t): extract from rb_io_t.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-11-18 13:58:47 +00:00
parent 9be87b1eb6
commit c6e4767068
3 changed files with 227 additions and 224 deletions

View File

@ -1,3 +1,7 @@
Thu Nov 18 22:58:43 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/io.h (rb_io_buffer_t): extract from rb_io_t.
Thu Nov 18 07:37:44 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> Thu Nov 18 07:37:44 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* Makefile.in (reconfig): force reconfigure with previous options. * Makefile.in (reconfig): force reconfigure with previous options.

View File

@ -31,6 +31,13 @@ extern "C" {
#pragma GCC visibility push(default) #pragma GCC visibility push(default)
#endif #endif
typedef struct {
char *ptr; /* off + len <= capa */
int off;
int len;
int capa;
} rb_io_buffer_t;
typedef struct rb_io_t { typedef struct rb_io_t {
int fd; /* file descriptor */ int fd; /* file descriptor */
FILE *stdio_file; /* stdio ptr for read/write if available */ FILE *stdio_file; /* stdio ptr for read/write if available */
@ -40,15 +47,7 @@ typedef struct rb_io_t {
VALUE pathv; /* pathname for file */ VALUE pathv; /* pathname for file */
void (*finalize)(struct rb_io_t*,int); /* finalize proc */ void (*finalize)(struct rb_io_t*,int); /* finalize proc */
char *wbuf; /* wbuf_off + wbuf_len <= wbuf_capa */ rb_io_buffer_t wbuf, rbuf;
int wbuf_off;
int wbuf_len;
int wbuf_capa;
char *rbuf; /* rbuf_off + rbuf_len <= rbuf_capa */
int rbuf_off;
int rbuf_len;
int rbuf_capa;
VALUE tied_io_for_writing; VALUE tied_io_for_writing;
@ -66,10 +65,7 @@ typedef struct rb_io_t {
} encs; } encs;
rb_econv_t *readconv; rb_econv_t *readconv;
char *cbuf; /* cbuf_off + cbuf_len <= cbuf_capa */ rb_io_buffer_t cbuf;
int cbuf_off;
int cbuf_len;
int cbuf_capa;
rb_econv_t *writeconv; rb_econv_t *writeconv;
VALUE writeconv_asciicompat; VALUE writeconv_asciicompat;
@ -101,6 +97,13 @@ typedef struct rb_io_t {
#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr) #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
#define RB_IO_BUFFER_INIT(buf) do {\
(buf).ptr = NULL;\
(buf).off = 0;\
(buf).len = 0;\
(buf).capa = 0;\
} while (0)
#define MakeOpenFile(obj, fp) do {\ #define MakeOpenFile(obj, fp) do {\
if (RFILE(obj)->fptr) {\ if (RFILE(obj)->fptr) {\
rb_io_close(obj);\ rb_io_close(obj);\
@ -108,7 +111,12 @@ typedef struct rb_io_t {
RFILE(obj)->fptr = 0;\ RFILE(obj)->fptr = 0;\
}\ }\
fp = 0;\ fp = 0;\
fp = RFILE(obj)->fptr = ALLOC(rb_io_t);\ RB_IO_FPTR_NEW(fp);\
RFILE(obj)->fptr = fp;\
} while (0)
#define RB_IO_FPTR_NEW(fp) do {\
fp = ALLOC(rb_io_t);\
fp->fd = -1;\ fp->fd = -1;\
fp->stdio_file = NULL;\ fp->stdio_file = NULL;\
fp->mode = 0;\ fp->mode = 0;\
@ -116,19 +124,10 @@ typedef struct rb_io_t {
fp->lineno = 0;\ fp->lineno = 0;\
fp->pathv = Qnil;\ fp->pathv = Qnil;\
fp->finalize = 0;\ fp->finalize = 0;\
fp->wbuf = NULL;\ RB_IO_BUFFER_INIT(fp->wbuf);\
fp->wbuf_off = 0;\ RB_IO_BUFFER_INIT(fp->rbuf);\
fp->wbuf_len = 0;\ RB_IO_BUFFER_INIT(fp->cbuf);\
fp->wbuf_capa = 0;\
fp->rbuf = NULL;\
fp->rbuf_off = 0;\
fp->rbuf_len = 0;\
fp->rbuf_capa = 0;\
fp->readconv = NULL;\ fp->readconv = NULL;\
fp->cbuf = NULL;\
fp->cbuf_off = 0;\
fp->cbuf_len = 0;\
fp->cbuf_capa = 0;\
fp->writeconv = NULL;\ fp->writeconv = NULL;\
fp->writeconv_asciicompat = Qnil;\ fp->writeconv_asciicompat = Qnil;\
fp->writeconv_pre_ecflags = 0;\ fp->writeconv_pre_ecflags = 0;\

396
io.c
View File

@ -181,14 +181,14 @@ static int max_file_descriptor = NOFILE;
#define GetWriteIO(io) rb_io_get_write_io(io) #define GetWriteIO(io) rb_io_get_write_io(io)
#define READ_DATA_PENDING(fptr) ((fptr)->rbuf_len) #define READ_DATA_PENDING(fptr) ((fptr)->rbuf.len)
#define READ_DATA_PENDING_COUNT(fptr) ((fptr)->rbuf_len) #define READ_DATA_PENDING_COUNT(fptr) ((fptr)->rbuf.len)
#define READ_DATA_PENDING_PTR(fptr) ((fptr)->rbuf+(fptr)->rbuf_off) #define READ_DATA_PENDING_PTR(fptr) ((fptr)->rbuf.ptr+(fptr)->rbuf.off)
#define READ_DATA_BUFFERED(fptr) READ_DATA_PENDING(fptr) #define READ_DATA_BUFFERED(fptr) READ_DATA_PENDING(fptr)
#define READ_CHAR_PENDING(fptr) ((fptr)->cbuf_len) #define READ_CHAR_PENDING(fptr) ((fptr)->cbuf.len)
#define READ_CHAR_PENDING_COUNT(fptr) ((fptr)->cbuf_len) #define READ_CHAR_PENDING_COUNT(fptr) ((fptr)->cbuf.len)
#define READ_CHAR_PENDING_PTR(fptr) ((fptr)->cbuf+(fptr)->cbuf_off) #define READ_CHAR_PENDING_PTR(fptr) ((fptr)->cbuf.ptr+(fptr)->cbuf.off)
#if defined(_WIN32) #if defined(_WIN32)
#define WAIT_FD_IN_WIN32(fptr) \ #define WAIT_FD_IN_WIN32(fptr) \
@ -354,18 +354,18 @@ io_unread(rb_io_t *fptr)
{ {
off_t r; off_t r;
rb_io_check_closed(fptr); rb_io_check_closed(fptr);
if (fptr->rbuf_len == 0 || fptr->mode & FMODE_DUPLEX) if (fptr->rbuf.len == 0 || fptr->mode & FMODE_DUPLEX)
return; return;
/* xxx: target position may be negative if buffer is filled by ungetc */ /* xxx: target position may be negative if buffer is filled by ungetc */
errno = 0; errno = 0;
r = lseek(fptr->fd, -fptr->rbuf_len, SEEK_CUR); r = lseek(fptr->fd, -fptr->rbuf.len, SEEK_CUR);
if (r < 0 && errno) { if (r < 0 && errno) {
if (errno == ESPIPE) if (errno == ESPIPE)
fptr->mode |= FMODE_DUPLEX; fptr->mode |= FMODE_DUPLEX;
return; return;
} }
fptr->rbuf_off = 0; fptr->rbuf.off = 0;
fptr->rbuf_len = 0; fptr->rbuf.len = 0;
return; return;
} }
@ -376,32 +376,32 @@ io_ungetbyte(VALUE str, rb_io_t *fptr)
{ {
long len = RSTRING_LEN(str); long len = RSTRING_LEN(str);
if (fptr->rbuf == NULL) { if (fptr->rbuf.ptr == NULL) {
const int min_capa = IO_RBUF_CAPA_FOR(fptr); const int min_capa = IO_RBUF_CAPA_FOR(fptr);
fptr->rbuf_off = 0; fptr->rbuf.off = 0;
fptr->rbuf_len = 0; fptr->rbuf.len = 0;
#if SIZEOF_LONG > SIZEOF_INT #if SIZEOF_LONG > SIZEOF_INT
if (len > INT_MAX) if (len > INT_MAX)
rb_raise(rb_eIOError, "ungetbyte failed"); rb_raise(rb_eIOError, "ungetbyte failed");
#endif #endif
if (len > min_capa) if (len > min_capa)
fptr->rbuf_capa = (int)len; fptr->rbuf.capa = (int)len;
else else
fptr->rbuf_capa = min_capa; fptr->rbuf.capa = min_capa;
fptr->rbuf = ALLOC_N(char, fptr->rbuf_capa); fptr->rbuf.ptr = ALLOC_N(char, fptr->rbuf.capa);
} }
if (fptr->rbuf_capa < len + fptr->rbuf_len) { if (fptr->rbuf.capa < len + fptr->rbuf.len) {
rb_raise(rb_eIOError, "ungetbyte failed"); rb_raise(rb_eIOError, "ungetbyte failed");
} }
if (fptr->rbuf_off < len) { if (fptr->rbuf.off < len) {
MEMMOVE(fptr->rbuf+fptr->rbuf_capa-fptr->rbuf_len, MEMMOVE(fptr->rbuf.ptr+fptr->rbuf.capa-fptr->rbuf.len,
fptr->rbuf+fptr->rbuf_off, fptr->rbuf.ptr+fptr->rbuf.off,
char, fptr->rbuf_len); char, fptr->rbuf.len);
fptr->rbuf_off = fptr->rbuf_capa-fptr->rbuf_len; fptr->rbuf.off = fptr->rbuf.capa-fptr->rbuf.len;
} }
fptr->rbuf_off-=(int)len; fptr->rbuf.off-=(int)len;
fptr->rbuf_len+=(int)len; fptr->rbuf.len+=(int)len;
MEMMOVE(fptr->rbuf+fptr->rbuf_off, RSTRING_PTR(str), char, len); MEMMOVE(fptr->rbuf.ptr+fptr->rbuf.off, RSTRING_PTR(str), char, len);
} }
static rb_io_t * static rb_io_t *
@ -432,7 +432,7 @@ rb_io_check_char_readable(rb_io_t *fptr)
if (!(fptr->mode & FMODE_READABLE)) { if (!(fptr->mode & FMODE_READABLE)) {
rb_raise(rb_eIOError, "not opened for reading"); rb_raise(rb_eIOError, "not opened for reading");
} }
if (fptr->wbuf_len) { if (fptr->wbuf.len) {
if (io_fflush(fptr) < 0) if (io_fflush(fptr) < 0)
rb_sys_fail(0); rb_sys_fail(0);
} }
@ -484,7 +484,7 @@ rb_io_check_writable(rb_io_t *fptr)
if (!(fptr->mode & FMODE_WRITABLE)) { if (!(fptr->mode & FMODE_WRITABLE)) {
rb_raise(rb_eIOError, "not opened for writing"); rb_raise(rb_eIOError, "not opened for writing");
} }
if (fptr->rbuf_len) { if (fptr->rbuf.len) {
io_unread(fptr); io_unread(fptr);
} }
} }
@ -635,17 +635,17 @@ static VALUE
io_flush_buffer_sync(void *arg) io_flush_buffer_sync(void *arg)
{ {
rb_io_t *fptr = arg; rb_io_t *fptr = arg;
long l = io_writable_length(fptr, fptr->wbuf_len); long l = io_writable_length(fptr, fptr->wbuf.len);
ssize_t r = write(fptr->fd, fptr->wbuf+fptr->wbuf_off, (size_t)l); ssize_t r = write(fptr->fd, fptr->wbuf.ptr+fptr->wbuf.off, (size_t)l);
if (fptr->wbuf_len <= r) { if (fptr->wbuf.len <= r) {
fptr->wbuf_off = 0; fptr->wbuf.off = 0;
fptr->wbuf_len = 0; fptr->wbuf.len = 0;
return 0; return 0;
} }
if (0 <= r) { if (0 <= r) {
fptr->wbuf_off += (int)r; fptr->wbuf.off += (int)r;
fptr->wbuf_len -= (int)r; fptr->wbuf.len -= (int)r;
errno = EAGAIN; errno = EAGAIN;
} }
return (VALUE)-1; return (VALUE)-1;
@ -672,12 +672,12 @@ static int
io_fflush(rb_io_t *fptr) io_fflush(rb_io_t *fptr)
{ {
rb_io_check_closed(fptr); rb_io_check_closed(fptr);
if (fptr->wbuf_len == 0) if (fptr->wbuf.len == 0)
return 0; return 0;
if (!rb_thread_fd_writable(fptr->fd)) { if (!rb_thread_fd_writable(fptr->fd)) {
rb_io_check_closed(fptr); rb_io_check_closed(fptr);
} }
while (fptr->wbuf_len > 0 && io_flush_buffer(fptr) != 0) { while (fptr->wbuf.len > 0 && io_flush_buffer(fptr) != 0) {
if (!rb_io_wait_writable(fptr->fd)) if (!rb_io_wait_writable(fptr->fd))
return -1; return -1;
rb_io_check_closed(fptr); rb_io_check_closed(fptr);
@ -856,25 +856,25 @@ io_binwrite(VALUE str, const char *ptr, long len, rb_io_t *fptr, int nosync)
long n, r, offset = 0; long n, r, offset = 0;
if ((n = len) <= 0) return n; if ((n = len) <= 0) return n;
if (fptr->wbuf == NULL && !(!nosync && (fptr->mode & FMODE_SYNC))) { if (fptr->wbuf.ptr == NULL && !(!nosync && (fptr->mode & FMODE_SYNC))) {
fptr->wbuf_off = 0; fptr->wbuf.off = 0;
fptr->wbuf_len = 0; fptr->wbuf.len = 0;
fptr->wbuf_capa = IO_WBUF_CAPA_MIN; fptr->wbuf.capa = IO_WBUF_CAPA_MIN;
fptr->wbuf = ALLOC_N(char, fptr->wbuf_capa); fptr->wbuf.ptr = ALLOC_N(char, fptr->wbuf.capa);
fptr->write_lock = rb_mutex_new(); fptr->write_lock = rb_mutex_new();
} }
if ((!nosync && (fptr->mode & (FMODE_SYNC|FMODE_TTY))) || if ((!nosync && (fptr->mode & (FMODE_SYNC|FMODE_TTY))) ||
(fptr->wbuf && fptr->wbuf_capa <= fptr->wbuf_len + len)) { (fptr->wbuf.ptr && fptr->wbuf.capa <= fptr->wbuf.len + len)) {
struct binwrite_arg arg; struct binwrite_arg arg;
/* xxx: use writev to avoid double write if available */ /* xxx: use writev to avoid double write if available */
if (fptr->wbuf_len && fptr->wbuf_len+len <= fptr->wbuf_capa) { if (fptr->wbuf.len && fptr->wbuf.len+len <= fptr->wbuf.capa) {
if (fptr->wbuf_capa < fptr->wbuf_off+fptr->wbuf_len+len) { if (fptr->wbuf.capa < fptr->wbuf.off+fptr->wbuf.len+len) {
MEMMOVE(fptr->wbuf, fptr->wbuf+fptr->wbuf_off, char, fptr->wbuf_len); MEMMOVE(fptr->wbuf.ptr, fptr->wbuf.ptr+fptr->wbuf.off, char, fptr->wbuf.len);
fptr->wbuf_off = 0; fptr->wbuf.off = 0;
} }
MEMMOVE(fptr->wbuf+fptr->wbuf_off+fptr->wbuf_len, ptr+offset, char, len); MEMMOVE(fptr->wbuf.ptr+fptr->wbuf.off+fptr->wbuf.len, ptr+offset, char, len);
fptr->wbuf_len += (int)len; fptr->wbuf.len += (int)len;
n = 0; n = 0;
} }
if (io_fflush(fptr) < 0) if (io_fflush(fptr) < 0)
@ -913,13 +913,13 @@ io_binwrite(VALUE str, const char *ptr, long len, rb_io_t *fptr, int nosync)
return -1L; return -1L;
} }
if (fptr->wbuf_off) { if (fptr->wbuf.off) {
if (fptr->wbuf_len) if (fptr->wbuf.len)
MEMMOVE(fptr->wbuf, fptr->wbuf+fptr->wbuf_off, char, fptr->wbuf_len); MEMMOVE(fptr->wbuf.ptr, fptr->wbuf.ptr+fptr->wbuf.off, char, fptr->wbuf.len);
fptr->wbuf_off = 0; fptr->wbuf.off = 0;
} }
MEMMOVE(fptr->wbuf+fptr->wbuf_off+fptr->wbuf_len, ptr+offset, char, len); MEMMOVE(fptr->wbuf.ptr+fptr->wbuf.off+fptr->wbuf.len, ptr+offset, char, len);
fptr->wbuf_len += (int)len; fptr->wbuf.len += (int)len;
return len; return len;
} }
@ -1120,7 +1120,7 @@ rb_io_tell(VALUE io)
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
pos = io_tell(fptr); pos = io_tell(fptr);
if (pos < 0 && errno) rb_sys_fail_path(fptr->pathv); if (pos < 0 && errno) rb_sys_fail_path(fptr->pathv);
pos -= fptr->rbuf_len; pos -= fptr->rbuf.len;
return OFFT2NUM(pos); return OFFT2NUM(pos);
} }
@ -1238,24 +1238,24 @@ io_fillbuf(rb_io_t *fptr)
{ {
ssize_t r; ssize_t r;
if (fptr->rbuf == NULL) { if (fptr->rbuf.ptr == NULL) {
fptr->rbuf_off = 0; fptr->rbuf.off = 0;
fptr->rbuf_len = 0; fptr->rbuf.len = 0;
fptr->rbuf_capa = IO_RBUF_CAPA_FOR(fptr); fptr->rbuf.capa = IO_RBUF_CAPA_FOR(fptr);
fptr->rbuf = ALLOC_N(char, fptr->rbuf_capa); fptr->rbuf.ptr = ALLOC_N(char, fptr->rbuf.capa);
} }
if (fptr->rbuf_len == 0) { if (fptr->rbuf.len == 0) {
retry: retry:
{ {
r = rb_read_internal(fptr->fd, fptr->rbuf, fptr->rbuf_capa); r = rb_read_internal(fptr->fd, fptr->rbuf.ptr, fptr->rbuf.capa);
} }
if (r < 0) { if (r < 0) {
if (rb_io_wait_readable(fptr->fd)) if (rb_io_wait_readable(fptr->fd))
goto retry; goto retry;
rb_sys_fail_path(fptr->pathv); rb_sys_fail_path(fptr->pathv);
} }
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)
return -1; /* EOF */ return -1; /* EOF */
} }
@ -1545,9 +1545,9 @@ read_buffered_data(char *ptr, long len, rb_io_t *fptr)
n = READ_DATA_PENDING_COUNT(fptr); n = READ_DATA_PENDING_COUNT(fptr);
if (n <= 0) return 0; if (n <= 0) return 0;
if (n > len) n = (int)len; if (n > len) n = (int)len;
MEMMOVE(ptr, fptr->rbuf+fptr->rbuf_off, char, n); MEMMOVE(ptr, fptr->rbuf.ptr+fptr->rbuf.off, char, n);
fptr->rbuf_off += n; fptr->rbuf.off += n;
fptr->rbuf_len -= n; fptr->rbuf.len -= n;
return n; return n;
} }
@ -1673,11 +1673,11 @@ make_readconv(rb_io_t *fptr, int size)
fptr->readconv = rb_econv_open_opts(sname, dname, ecflags, ecopts); fptr->readconv = rb_econv_open_opts(sname, dname, ecflags, ecopts);
if (!fptr->readconv) if (!fptr->readconv)
rb_exc_raise(rb_econv_open_exc(sname, dname, ecflags)); rb_exc_raise(rb_econv_open_exc(sname, dname, ecflags));
fptr->cbuf_off = 0; fptr->cbuf.off = 0;
fptr->cbuf_len = 0; fptr->cbuf.len = 0;
if (size < IO_CBUF_CAPA_MIN) size = IO_CBUF_CAPA_MIN; if (size < IO_CBUF_CAPA_MIN) size = IO_CBUF_CAPA_MIN;
fptr->cbuf_capa = size; fptr->cbuf.capa = size;
fptr->cbuf = ALLOC_N(char, fptr->cbuf_capa); fptr->cbuf.ptr = ALLOC_N(char, fptr->cbuf.capa);
} }
} }
@ -1695,39 +1695,39 @@ fill_cbuf(rb_io_t *fptr, int ec_flags)
ec_flags |= ECONV_PARTIAL_INPUT; ec_flags |= ECONV_PARTIAL_INPUT;
if (fptr->cbuf_len == fptr->cbuf_capa) if (fptr->cbuf.len == fptr->cbuf.capa)
return MORE_CHAR_SUSPENDED; /* cbuf full */ return MORE_CHAR_SUSPENDED; /* cbuf full */
if (fptr->cbuf_len == 0) if (fptr->cbuf.len == 0)
fptr->cbuf_off = 0; fptr->cbuf.off = 0;
else if (fptr->cbuf_off + fptr->cbuf_len == fptr->cbuf_capa) { else if (fptr->cbuf.off + fptr->cbuf.len == fptr->cbuf.capa) {
memmove(fptr->cbuf, fptr->cbuf+fptr->cbuf_off, fptr->cbuf_len); memmove(fptr->cbuf.ptr, fptr->cbuf.ptr+fptr->cbuf.off, fptr->cbuf.len);
fptr->cbuf_off = 0; fptr->cbuf.off = 0;
} }
cbuf_len0 = fptr->cbuf_len; cbuf_len0 = fptr->cbuf.len;
while (1) { while (1) {
ss = sp = (const unsigned char *)fptr->rbuf + fptr->rbuf_off; ss = sp = (const unsigned char *)fptr->rbuf.ptr + fptr->rbuf.off;
se = sp + fptr->rbuf_len; se = sp + fptr->rbuf.len;
ds = dp = (unsigned char *)fptr->cbuf + fptr->cbuf_off + fptr->cbuf_len; ds = dp = (unsigned char *)fptr->cbuf.ptr + fptr->cbuf.off + fptr->cbuf.len;
de = (unsigned char *)fptr->cbuf + fptr->cbuf_capa; de = (unsigned char *)fptr->cbuf.ptr + fptr->cbuf.capa;
res = rb_econv_convert(fptr->readconv, &sp, se, &dp, de, ec_flags); res = rb_econv_convert(fptr->readconv, &sp, se, &dp, de, ec_flags);
fptr->rbuf_off += (int)(sp - ss); fptr->rbuf.off += (int)(sp - ss);
fptr->rbuf_len -= (int)(sp - ss); fptr->rbuf.len -= (int)(sp - ss);
fptr->cbuf_len += (int)(dp - ds); fptr->cbuf.len += (int)(dp - ds);
putbackable = rb_econv_putbackable(fptr->readconv); putbackable = rb_econv_putbackable(fptr->readconv);
if (putbackable) { if (putbackable) {
rb_econv_putback(fptr->readconv, (unsigned char *)fptr->rbuf + fptr->rbuf_off - putbackable, putbackable); rb_econv_putback(fptr->readconv, (unsigned char *)fptr->rbuf.ptr + fptr->rbuf.off - putbackable, putbackable);
fptr->rbuf_off -= putbackable; fptr->rbuf.off -= putbackable;
fptr->rbuf_len += putbackable; fptr->rbuf.len += putbackable;
} }
exc = rb_econv_make_exception(fptr->readconv); exc = rb_econv_make_exception(fptr->readconv);
if (!NIL_P(exc)) if (!NIL_P(exc))
return exc; return exc;
if (cbuf_len0 != fptr->cbuf_len) if (cbuf_len0 != fptr->cbuf.len)
return MORE_CHAR_SUSPENDED; return MORE_CHAR_SUSPENDED;
if (res == econv_finished) { if (res == econv_finished) {
@ -1735,13 +1735,13 @@ fill_cbuf(rb_io_t *fptr, int ec_flags)
} }
if (res == econv_source_buffer_empty) { if (res == econv_source_buffer_empty) {
if (fptr->rbuf_len == 0) { if (fptr->rbuf.len == 0) {
READ_CHECK(fptr); READ_CHECK(fptr);
if (io_fillbuf(fptr) == -1) { if (io_fillbuf(fptr) == -1) {
ds = dp = (unsigned char *)fptr->cbuf + fptr->cbuf_off + fptr->cbuf_len; ds = dp = (unsigned char *)fptr->cbuf.ptr + fptr->cbuf.off + fptr->cbuf.len;
de = (unsigned char *)fptr->cbuf + fptr->cbuf_capa; de = (unsigned char *)fptr->cbuf.ptr + fptr->cbuf.capa;
res = rb_econv_convert(fptr->readconv, NULL, NULL, &dp, de, 0); res = rb_econv_convert(fptr->readconv, NULL, NULL, &dp, de, 0);
fptr->cbuf_len += (int)(dp - ds); fptr->cbuf.len += (int)(dp - ds);
rb_econv_check_error(fptr->readconv); rb_econv_check_error(fptr->readconv);
} }
} }
@ -1766,22 +1766,22 @@ io_shift_cbuf(rb_io_t *fptr, int len, VALUE *strp)
if (strp) { if (strp) {
str = *strp; str = *strp;
if (NIL_P(str)) { if (NIL_P(str)) {
*strp = str = rb_str_new(fptr->cbuf+fptr->cbuf_off, len); *strp = str = rb_str_new(fptr->cbuf.ptr+fptr->cbuf.off, len);
} }
else { else {
rb_str_cat(str, fptr->cbuf+fptr->cbuf_off, len); rb_str_cat(str, fptr->cbuf.ptr+fptr->cbuf.off, len);
} }
OBJ_TAINT(str); OBJ_TAINT(str);
rb_enc_associate(str, fptr->encs.enc); rb_enc_associate(str, fptr->encs.enc);
} }
fptr->cbuf_off += len; fptr->cbuf.off += len;
fptr->cbuf_len -= len; fptr->cbuf.len -= len;
/* xxx: set coderange */ /* xxx: set coderange */
if (fptr->cbuf_len == 0) if (fptr->cbuf.len == 0)
fptr->cbuf_off = 0; fptr->cbuf.off = 0;
else if (fptr->cbuf_capa/2 < fptr->cbuf_off) { else if (fptr->cbuf.capa/2 < fptr->cbuf.off) {
memmove(fptr->cbuf, fptr->cbuf+fptr->cbuf_off, fptr->cbuf_len); memmove(fptr->cbuf.ptr, fptr->cbuf.ptr+fptr->cbuf.off, fptr->cbuf.len);
fptr->cbuf_off = 0; fptr->cbuf.off = 0;
} }
return str; return str;
} }
@ -1801,13 +1801,13 @@ read_all(rb_io_t *fptr, long siz, VALUE str)
make_readconv(fptr, 0); make_readconv(fptr, 0);
while (1) { while (1) {
VALUE v; VALUE v;
if (fptr->cbuf_len) { if (fptr->cbuf.len) {
io_shift_cbuf(fptr, fptr->cbuf_len, &str); io_shift_cbuf(fptr, fptr->cbuf.len, &str);
} }
v = fill_cbuf(fptr, 0); v = fill_cbuf(fptr, 0);
if (v != MORE_CHAR_SUSPENDED && v != MORE_CHAR_FINISHED) { if (v != MORE_CHAR_SUSPENDED && v != MORE_CHAR_FINISHED) {
if (fptr->cbuf_len) { if (fptr->cbuf.len) {
io_shift_cbuf(fptr, fptr->cbuf_len, &str); io_shift_cbuf(fptr, fptr->cbuf.len, &str);
} }
rb_exc_raise(v); rb_exc_raise(v);
} }
@ -2264,9 +2264,9 @@ appendline(rb_io_t *fptr, int delim, VALUE *strp, long *lp)
do { do {
const char *p, *e; const char *p, *e;
int searchlen; int searchlen;
if (fptr->cbuf_len) { if (fptr->cbuf.len) {
p = fptr->cbuf+fptr->cbuf_off; p = fptr->cbuf.ptr+fptr->cbuf.off;
searchlen = fptr->cbuf_len; searchlen = fptr->cbuf.len;
if (0 < limit && limit < searchlen) if (0 < limit && limit < searchlen)
searchlen = (int)limit; searchlen = (int)limit;
e = memchr(p, delim, searchlen); e = memchr(p, delim, searchlen);
@ -2276,8 +2276,8 @@ appendline(rb_io_t *fptr, int delim, VALUE *strp, long *lp)
*strp = str = rb_str_new(p, len); *strp = str = rb_str_new(p, len);
else else
rb_str_buf_cat(str, p, len); rb_str_buf_cat(str, p, len);
fptr->cbuf_off += len; fptr->cbuf.off += len;
fptr->cbuf_len -= len; fptr->cbuf.len -= len;
limit -= len; limit -= len;
*lp = limit; *lp = limit;
return delim; return delim;
@ -2287,8 +2287,8 @@ appendline(rb_io_t *fptr, int delim, VALUE *strp, long *lp)
*strp = str = rb_str_new(p, searchlen); *strp = str = rb_str_new(p, searchlen);
else else
rb_str_buf_cat(str, p, searchlen); rb_str_buf_cat(str, p, searchlen);
fptr->cbuf_off += searchlen; fptr->cbuf.off += searchlen;
fptr->cbuf_len -= searchlen; fptr->cbuf.len -= searchlen;
limit -= searchlen; limit -= searchlen;
if (limit == 0) { if (limit == 0) {
@ -2402,8 +2402,8 @@ rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc, VALUE io)
} }
if (NIL_P(str)) { if (NIL_P(str)) {
str = rb_str_new(p, pending); str = rb_str_new(p, pending);
fptr->rbuf_off += pending; fptr->rbuf.off += pending;
fptr->rbuf_len -= pending; fptr->rbuf.len -= pending;
} }
else { else {
rb_str_resize(str, len + pending); rb_str_resize(str, len + pending);
@ -2829,11 +2829,11 @@ rb_io_each_byte(VALUE io)
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
for (;;) { for (;;) {
p = fptr->rbuf+fptr->rbuf_off; p = fptr->rbuf.ptr+fptr->rbuf.off;
e = p + fptr->rbuf_len; e = p + fptr->rbuf.len;
while (p < e) { while (p < e) {
fptr->rbuf_off++; fptr->rbuf.off++;
fptr->rbuf_len--; fptr->rbuf.len--;
rb_yield(INT2FIX(*p & 0xff)); rb_yield(INT2FIX(*p & 0xff));
p++; p++;
errno = 0; errno = 0;
@ -2860,34 +2860,34 @@ io_getc(rb_io_t *fptr, rb_encoding *enc)
make_readconv(fptr, 0); make_readconv(fptr, 0);
while (1) { while (1) {
if (fptr->cbuf_len) { if (fptr->cbuf.len) {
r = rb_enc_precise_mbclen(fptr->cbuf+fptr->cbuf_off, r = rb_enc_precise_mbclen(fptr->cbuf.ptr+fptr->cbuf.off,
fptr->cbuf+fptr->cbuf_off+fptr->cbuf_len, fptr->cbuf.ptr+fptr->cbuf.off+fptr->cbuf.len,
read_enc); read_enc);
if (!MBCLEN_NEEDMORE_P(r)) if (!MBCLEN_NEEDMORE_P(r))
break; break;
if (fptr->cbuf_len == fptr->cbuf_capa) { if (fptr->cbuf.len == fptr->cbuf.capa) {
rb_raise(rb_eIOError, "too long character"); rb_raise(rb_eIOError, "too long character");
} }
} }
if (more_char(fptr) == MORE_CHAR_FINISHED) { if (more_char(fptr) == MORE_CHAR_FINISHED) {
if (fptr->cbuf_len == 0) { if (fptr->cbuf.len == 0) {
clear_readconv(fptr); clear_readconv(fptr);
return Qnil; return Qnil;
} }
/* return an unit of an incomplete character just before EOF */ /* return an unit of an incomplete character just before EOF */
str = rb_enc_str_new(fptr->cbuf+fptr->cbuf_off, 1, read_enc); str = rb_enc_str_new(fptr->cbuf.ptr+fptr->cbuf.off, 1, read_enc);
fptr->cbuf_off += 1; fptr->cbuf.off += 1;
fptr->cbuf_len -= 1; fptr->cbuf.len -= 1;
if (fptr->cbuf_len == 0) clear_readconv(fptr); if (fptr->cbuf.len == 0) clear_readconv(fptr);
ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN); ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN);
return str; return str;
} }
} }
if (MBCLEN_INVALID_P(r)) { if (MBCLEN_INVALID_P(r)) {
r = rb_enc_mbclen(fptr->cbuf+fptr->cbuf_off, r = rb_enc_mbclen(fptr->cbuf.ptr+fptr->cbuf.off,
fptr->cbuf+fptr->cbuf_off+fptr->cbuf_len, fptr->cbuf.ptr+fptr->cbuf.off+fptr->cbuf.len,
read_enc); read_enc);
io_shift_cbuf(fptr, r, &str); io_shift_cbuf(fptr, r, &str);
cr = ENC_CODERANGE_BROKEN; cr = ENC_CODERANGE_BROKEN;
@ -2904,29 +2904,29 @@ io_getc(rb_io_t *fptr, rb_encoding *enc)
if (io_fillbuf(fptr) < 0) { if (io_fillbuf(fptr) < 0) {
return Qnil; return Qnil;
} }
if (rb_enc_asciicompat(enc) && ISASCII(fptr->rbuf[fptr->rbuf_off])) { if (rb_enc_asciicompat(enc) && ISASCII(fptr->rbuf.ptr[fptr->rbuf.off])) {
str = rb_str_new(fptr->rbuf+fptr->rbuf_off, 1); str = rb_str_new(fptr->rbuf.ptr+fptr->rbuf.off, 1);
fptr->rbuf_off += 1; fptr->rbuf.off += 1;
fptr->rbuf_len -= 1; fptr->rbuf.len -= 1;
cr = ENC_CODERANGE_7BIT; cr = ENC_CODERANGE_7BIT;
} }
else { else {
r = rb_enc_precise_mbclen(fptr->rbuf+fptr->rbuf_off, fptr->rbuf+fptr->rbuf_off+fptr->rbuf_len, enc); r = rb_enc_precise_mbclen(fptr->rbuf.ptr+fptr->rbuf.off, fptr->rbuf.ptr+fptr->rbuf.off+fptr->rbuf.len, enc);
if (MBCLEN_CHARFOUND_P(r) && if (MBCLEN_CHARFOUND_P(r) &&
(n = MBCLEN_CHARFOUND_LEN(r)) <= fptr->rbuf_len) { (n = MBCLEN_CHARFOUND_LEN(r)) <= fptr->rbuf.len) {
str = rb_str_new(fptr->rbuf+fptr->rbuf_off, n); str = rb_str_new(fptr->rbuf.ptr+fptr->rbuf.off, n);
fptr->rbuf_off += n; fptr->rbuf.off += n;
fptr->rbuf_len -= n; fptr->rbuf.len -= n;
cr = ENC_CODERANGE_VALID; cr = ENC_CODERANGE_VALID;
} }
else if (MBCLEN_NEEDMORE_P(r)) { else if (MBCLEN_NEEDMORE_P(r)) {
str = rb_str_new(fptr->rbuf+fptr->rbuf_off, fptr->rbuf_len); str = rb_str_new(fptr->rbuf.ptr+fptr->rbuf.off, fptr->rbuf.len);
fptr->rbuf_len = 0; fptr->rbuf.len = 0;
getc_needmore: getc_needmore:
if (io_fillbuf(fptr) != -1) { if (io_fillbuf(fptr) != -1) {
rb_str_cat(str, fptr->rbuf+fptr->rbuf_off, 1); rb_str_cat(str, fptr->rbuf.ptr+fptr->rbuf.off, 1);
fptr->rbuf_off++; fptr->rbuf.off++;
fptr->rbuf_len--; fptr->rbuf.len--;
r = rb_enc_precise_mbclen(RSTRING_PTR(str), RSTRING_PTR(str)+RSTRING_LEN(str), enc); r = rb_enc_precise_mbclen(RSTRING_PTR(str), RSTRING_PTR(str)+RSTRING_LEN(str), enc);
if (MBCLEN_NEEDMORE_P(r)) { if (MBCLEN_NEEDMORE_P(r)) {
goto getc_needmore; goto getc_needmore;
@ -2937,9 +2937,9 @@ io_getc(rb_io_t *fptr, rb_encoding *enc)
} }
} }
else { else {
str = rb_str_new(fptr->rbuf+fptr->rbuf_off, 1); str = rb_str_new(fptr->rbuf.ptr+fptr->rbuf.off, 1);
fptr->rbuf_off++; fptr->rbuf.off++;
fptr->rbuf_len--; fptr->rbuf.len--;
} }
} }
if (!cr) cr = ENC_CODERANGE_BROKEN; if (!cr) cr = ENC_CODERANGE_BROKEN;
@ -3018,16 +3018,16 @@ rb_io_each_codepoint(VALUE io)
for (;;) { for (;;) {
make_readconv(fptr, 0); make_readconv(fptr, 0);
for (;;) { for (;;) {
if (fptr->cbuf_len) { if (fptr->cbuf.len) {
if (fptr->encs.enc) if (fptr->encs.enc)
r = rb_enc_precise_mbclen(fptr->cbuf+fptr->cbuf_off, r = rb_enc_precise_mbclen(fptr->cbuf.ptr+fptr->cbuf.off,
fptr->cbuf+fptr->cbuf_off+fptr->cbuf_len, fptr->cbuf.ptr+fptr->cbuf.off+fptr->cbuf.len,
fptr->encs.enc); fptr->encs.enc);
else else
r = ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1); r = ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1);
if (!MBCLEN_NEEDMORE_P(r)) if (!MBCLEN_NEEDMORE_P(r))
break; break;
if (fptr->cbuf_len == fptr->cbuf_capa) { if (fptr->cbuf.len == fptr->cbuf.capa) {
rb_raise(rb_eIOError, "too long character"); rb_raise(rb_eIOError, "too long character");
} }
} }
@ -3043,15 +3043,15 @@ rb_io_each_codepoint(VALUE io)
} }
n = MBCLEN_CHARFOUND_LEN(r); n = MBCLEN_CHARFOUND_LEN(r);
if (fptr->encs.enc) { if (fptr->encs.enc) {
c = rb_enc_codepoint(fptr->cbuf+fptr->cbuf_off, c = rb_enc_codepoint(fptr->cbuf.ptr+fptr->cbuf.off,
fptr->cbuf+fptr->cbuf_off+fptr->cbuf_len, fptr->cbuf.ptr+fptr->cbuf.off+fptr->cbuf.len,
fptr->encs.enc); fptr->encs.enc);
} }
else { else {
c = (unsigned char)fptr->cbuf[fptr->cbuf_off]; c = (unsigned char)fptr->cbuf.ptr[fptr->cbuf.off];
} }
fptr->cbuf_off += n; fptr->cbuf.off += n;
fptr->cbuf_len -= n; fptr->cbuf.len -= n;
rb_yield(UINT2NUM(c)); rb_yield(UINT2NUM(c));
} }
} }
@ -3060,14 +3060,14 @@ rb_io_each_codepoint(VALUE io)
if (io_fillbuf(fptr) < 0) { if (io_fillbuf(fptr) < 0) {
return io; return io;
} }
r = rb_enc_precise_mbclen(fptr->rbuf+fptr->rbuf_off, r = rb_enc_precise_mbclen(fptr->rbuf.ptr+fptr->rbuf.off,
fptr->rbuf+fptr->rbuf_off+fptr->rbuf_len, enc); fptr->rbuf.ptr+fptr->rbuf.off+fptr->rbuf.len, enc);
if (MBCLEN_CHARFOUND_P(r) && if (MBCLEN_CHARFOUND_P(r) &&
(n = MBCLEN_CHARFOUND_LEN(r)) <= fptr->rbuf_len) { (n = MBCLEN_CHARFOUND_LEN(r)) <= fptr->rbuf.len) {
c = rb_enc_codepoint(fptr->rbuf+fptr->rbuf_off, c = rb_enc_codepoint(fptr->rbuf.ptr+fptr->rbuf.off,
fptr->rbuf+fptr->rbuf_off+fptr->rbuf_len, enc); fptr->rbuf.ptr+fptr->rbuf.off+fptr->rbuf.len, enc);
fptr->rbuf_off += n; fptr->rbuf.off += n;
fptr->rbuf_len -= n; fptr->rbuf.len -= n;
rb_yield(UINT2NUM(c)); rb_yield(UINT2NUM(c));
} }
else if (MBCLEN_INVALID_P(r)) { else if (MBCLEN_INVALID_P(r)) {
@ -3162,9 +3162,9 @@ rb_io_getbyte(VALUE io)
if (io_fillbuf(fptr) < 0) { if (io_fillbuf(fptr) < 0) {
return Qnil; return Qnil;
} }
fptr->rbuf_off++; fptr->rbuf.off++;
fptr->rbuf_len--; fptr->rbuf.len--;
c = (unsigned char)fptr->rbuf[fptr->rbuf_off-1]; c = (unsigned char)fptr->rbuf.ptr[fptr->rbuf.off-1];
return INT2FIX(c & 0xff); return INT2FIX(c & 0xff);
} }
@ -3264,17 +3264,17 @@ rb_io_ungetc(VALUE io, VALUE c)
rb_raise(rb_eIOError, "ungetc failed"); rb_raise(rb_eIOError, "ungetc failed");
#endif #endif
make_readconv(fptr, (int)len); make_readconv(fptr, (int)len);
if (fptr->cbuf_capa - fptr->cbuf_len < len) if (fptr->cbuf.capa - fptr->cbuf.len < len)
rb_raise(rb_eIOError, "ungetc failed"); rb_raise(rb_eIOError, "ungetc failed");
if (fptr->cbuf_off < len) { if (fptr->cbuf.off < len) {
MEMMOVE(fptr->cbuf+fptr->cbuf_capa-fptr->cbuf_len, MEMMOVE(fptr->cbuf.ptr+fptr->cbuf.capa-fptr->cbuf.len,
fptr->cbuf+fptr->cbuf_off, fptr->cbuf.ptr+fptr->cbuf.off,
char, fptr->cbuf_len); char, fptr->cbuf.len);
fptr->cbuf_off = fptr->cbuf_capa-fptr->cbuf_len; fptr->cbuf.off = fptr->cbuf.capa-fptr->cbuf.len;
} }
fptr->cbuf_off -= (int)len; fptr->cbuf.off -= (int)len;
fptr->cbuf_len += (int)len; fptr->cbuf.len += (int)len;
MEMMOVE(fptr->cbuf+fptr->cbuf_off, RSTRING_PTR(c), char, len); MEMMOVE(fptr->cbuf.ptr+fptr->cbuf.off, RSTRING_PTR(c), char, len);
} }
else { else {
io_ungetbyte(c, fptr); io_ungetbyte(c, fptr);
@ -3407,7 +3407,7 @@ finish_writeconv(rb_io_t *fptr, int noalloc)
unsigned char *ds, *dp, *de; unsigned char *ds, *dp, *de;
rb_econv_result_t res; rb_econv_result_t res;
if (!fptr->wbuf) { if (!fptr->wbuf.ptr) {
unsigned char buf[1024]; unsigned char buf[1024];
long r; long r;
@ -3443,15 +3443,15 @@ finish_writeconv(rb_io_t *fptr, int noalloc)
res = econv_destination_buffer_full; res = econv_destination_buffer_full;
while (res == econv_destination_buffer_full) { while (res == econv_destination_buffer_full) {
if (fptr->wbuf_len == fptr->wbuf_capa) { if (fptr->wbuf.len == fptr->wbuf.capa) {
if (io_fflush(fptr) < 0) if (io_fflush(fptr) < 0)
return noalloc ? Qtrue : INT2NUM(errno); return noalloc ? Qtrue : INT2NUM(errno);
} }
ds = dp = (unsigned char *)fptr->wbuf + fptr->wbuf_off + fptr->wbuf_len; ds = dp = (unsigned char *)fptr->wbuf.ptr + fptr->wbuf.off + fptr->wbuf.len;
de = (unsigned char *)fptr->wbuf + fptr->wbuf_capa; de = (unsigned char *)fptr->wbuf.ptr + fptr->wbuf.capa;
res = rb_econv_convert(fptr->writeconv, NULL, NULL, &dp, de, 0); res = rb_econv_convert(fptr->writeconv, NULL, NULL, &dp, de, 0);
fptr->wbuf_len += (int)(dp - ds); fptr->wbuf.len += (int)(dp - ds);
if (res == econv_invalid_byte_sequence || if (res == econv_invalid_byte_sequence ||
res == econv_incomplete_input || res == econv_incomplete_input ||
res == econv_undefined_conversion) { res == econv_undefined_conversion) {
@ -3488,7 +3488,7 @@ fptr_finalize(rb_io_t *fptr, int noraise)
err = finish_writeconv(fptr, noraise); err = finish_writeconv(fptr, noraise);
} }
} }
if (fptr->wbuf_len) { if (fptr->wbuf.len) {
if (noraise) { if (noraise) {
if ((int)io_flush_buffer_sync(fptr) < 0 && NIL_P(err)) if ((int)io_flush_buffer_sync(fptr) < 0 && NIL_P(err))
err = Qtrue; err = Qtrue;
@ -3550,9 +3550,9 @@ clear_readconv(rb_io_t *fptr)
rb_econv_close(fptr->readconv); rb_econv_close(fptr->readconv);
fptr->readconv = NULL; fptr->readconv = NULL;
} }
if (fptr->cbuf) { if (fptr->cbuf.ptr) {
free(fptr->cbuf); free(fptr->cbuf.ptr);
fptr->cbuf = NULL; fptr->cbuf.ptr = NULL;
} }
} }
@ -3581,13 +3581,13 @@ rb_io_fptr_finalize(rb_io_t *fptr)
if (0 <= fptr->fd) if (0 <= fptr->fd)
rb_io_fptr_cleanup(fptr, TRUE); rb_io_fptr_cleanup(fptr, TRUE);
fptr->write_lock = 0; fptr->write_lock = 0;
if (fptr->rbuf) { if (fptr->rbuf.ptr) {
free(fptr->rbuf); free(fptr->rbuf.ptr);
fptr->rbuf = 0; fptr->rbuf.ptr = 0;
} }
if (fptr->wbuf) { if (fptr->wbuf.ptr) {
free(fptr->wbuf); free(fptr->wbuf.ptr);
fptr->wbuf = 0; fptr->wbuf.ptr = 0;
} }
clear_codeconv(fptr); clear_codeconv(fptr);
free(fptr); free(fptr);
@ -3600,9 +3600,9 @@ RUBY_FUNC_EXPORTED size_t
rb_io_memsize(const rb_io_t *fptr) rb_io_memsize(const rb_io_t *fptr)
{ {
size_t size = sizeof(rb_io_t); size_t size = sizeof(rb_io_t);
size += fptr->rbuf_capa; size += fptr->rbuf.capa;
size += fptr->wbuf_capa; size += fptr->wbuf.capa;
size += fptr->cbuf_capa; size += fptr->cbuf.capa;
if (fptr->readconv) size += rb_econv_memsize(fptr->readconv); if (fptr->readconv) size += rb_econv_memsize(fptr->readconv);
if (fptr->writeconv) size += rb_econv_memsize(fptr->writeconv); if (fptr->writeconv) size += rb_econv_memsize(fptr->writeconv);
return size; return size;
@ -3858,7 +3858,7 @@ rb_io_sysseek(int argc, VALUE *argv, VALUE io)
(READ_DATA_BUFFERED(fptr) || READ_CHAR_PENDING(fptr))) { (READ_DATA_BUFFERED(fptr) || READ_CHAR_PENDING(fptr))) {
rb_raise(rb_eIOError, "sysseek for buffered IO"); rb_raise(rb_eIOError, "sysseek for buffered IO");
} }
if ((fptr->mode & FMODE_WRITABLE) && fptr->wbuf_len) { if ((fptr->mode & FMODE_WRITABLE) && fptr->wbuf.len) {
rb_warn("sysseek for buffered IO"); rb_warn("sysseek for buffered IO");
} }
errno = 0; errno = 0;
@ -3895,7 +3895,7 @@ rb_io_syswrite(VALUE io, VALUE str)
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
rb_io_check_writable(fptr); rb_io_check_writable(fptr);
if (fptr->wbuf_len) { if (fptr->wbuf.len) {
rb_warn("syswrite for buffered IO"); rb_warn("syswrite for buffered IO");
} }
if (!rb_thread_fd_writable(fptr->fd)) { if (!rb_thread_fd_writable(fptr->fd)) {
@ -5859,7 +5859,7 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file)
if (io_fflush(fptr) < 0) if (io_fflush(fptr) < 0)
rb_sys_fail(0); rb_sys_fail(0);
} }
fptr->rbuf_off = fptr->rbuf_len = 0; fptr->rbuf.off = fptr->rbuf.len = 0;
if (fptr->stdio_file) { if (fptr->stdio_file) {
if (freopen(RSTRING_PTR(fptr->pathv), rb_io_oflags_modestr(oflags), fptr->stdio_file) == 0) { if (freopen(RSTRING_PTR(fptr->pathv), rb_io_oflags_modestr(oflags), fptr->stdio_file) == 0) {
@ -8588,8 +8588,8 @@ copy_stream_body(VALUE arg)
} }
stp->dst_fd = dst_fd; stp->dst_fd = dst_fd;
if (stp->src_offset == (off_t)-1 && src_fptr && src_fptr->rbuf_len) { if (stp->src_offset == (off_t)-1 && src_fptr && src_fptr->rbuf.len) {
size_t len = src_fptr->rbuf_len; size_t len = src_fptr->rbuf.len;
VALUE str; VALUE str;
if (stp->copy_length != (off_t)-1 && stp->copy_length < (off_t)len) { if (stp->copy_length != (off_t)-1 && stp->copy_length < (off_t)len) {
len = (size_t)stp->copy_length; len = (size_t)stp->copy_length;