From 6f4d6b165042d6045f8de378bfd3d00d89f3f2ed Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 30 Jan 2008 21:24:24 +0000 Subject: [PATCH] * io.c (rb_io_close_read): replaces fptr with the tied writer if duplex. * io.c (rb_io_close_write): unties the tied IO for writing if duplex. [ruby-dev:33532] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ io.c | 25 ++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 077e752802..9bc2b66e8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Thu Jan 31 06:24:22 2008 Nobuyoshi Nakada + + * io.c (rb_io_close_read): replaces fptr with the tied writer if + duplex. + + * io.c (rb_io_close_write): unties the tied IO for writing if duplex. + [ruby-dev:33532] + Thu Jan 31 02:22:04 2008 Yukihiro Matsumoto * io.c (open_key_args): allow encoding key to take two encoding diff --git a/io.c b/io.c index 749229e335..b20b0fd4a9 100644 --- a/io.c +++ b/io.c @@ -2298,7 +2298,7 @@ rb_io_getc(VALUE io) else if (MBCLEN_NEEDMORE_P(r)) { str = rb_str_new(fptr->rbuf+fptr->rbuf_off, fptr->rbuf_len); fptr->rbuf_len = 0; -getc_needmore: + getc_needmore: if (io_fillbuf(fptr) != -1) { rb_str_cat(str, fptr->rbuf+fptr->rbuf_off, 1); fptr->rbuf_off++; @@ -2784,7 +2784,14 @@ rb_io_close_read(VALUE io) write_io = GetWriteIO(io); if (io != write_io) { + rb_io_t *wfptr; fptr_finalize(fptr, Qfalse); + GetOpenFile(write_io, wfptr); + if (fptr->refcnt < LONG_MAX) { + wfptr->refcnt++; + RFILE(io)->fptr = wfptr; + rb_io_fptr_finalize(fptr); + } return Qnil; } @@ -2817,12 +2824,13 @@ static VALUE rb_io_close_write(VALUE io) { rb_io_t *fptr; + VALUE write_io; if (rb_safe_level() >= 4 && !OBJ_TAINTED(io)) { rb_raise(rb_eSecurityError, "Insecure: can't close"); } - io = GetWriteIO(io); - GetOpenFile(io, fptr); + write_io = GetWriteIO(io); + GetOpenFile(write_io, fptr); if (is_socket(fptr->fd, fptr->path)) { #ifndef SHUT_WR # define SHUT_WR 1 @@ -2831,14 +2839,21 @@ rb_io_close_write(VALUE io) rb_sys_fail(fptr->path); fptr->mode &= ~FMODE_WRITABLE; if (!(fptr->mode & FMODE_READABLE)) - return rb_io_close(io); + return rb_io_close(write_io); return Qnil; } if (fptr->mode & FMODE_READABLE) { rb_raise(rb_eIOError, "closing non-duplex IO for writing"); } - return rb_io_close(io); + + rb_io_close(write_io); + if (io != write_io) { + GetOpenFile(io, fptr); + fptr->tied_io_for_writing = 0; + fptr->mode &= ~FMODE_DUPLEX; + } + return Qnil; } /*