From 507f89d33fb2c3fb7180dfda1a27364819f67f32 Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 9 Jun 2008 08:48:41 +0000 Subject: * io.c (fptr_finalize): close IO object if fd is already closed. (rb_p): call rb_io_write just once. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 27bfec1c16..2cad50cc05 100644 --- a/io.c +++ b/io.c @@ -2673,6 +2673,7 @@ rb_io_set_close_on_exec(VALUE io, VALUE arg) static void fptr_finalize(rb_io_t *fptr, int noraise) { + int ebadf = 0; if (fptr->wbuf_len) { io_fflush(fptr); } @@ -2690,13 +2691,22 @@ fptr_finalize(rb_io_t *fptr, int noraise) } else if (0 <= fptr->fd) { if (close(fptr->fd) < 0 && !noraise) { - /* fptr->fd is still not closed */ - rb_sys_fail(fptr->path); + if (errno != EBADF) { + /* fptr->fd is still not closed */ + rb_sys_fail(fptr->path); + } + else { + /* fptr->fd is already closed. */ + ebadf = 1; + } } } fptr->fd = -1; fptr->stdio_file = 0; fptr->mode &= ~(FMODE_READABLE|FMODE_WRITABLE); + if (ebadf) { + rb_sys_fail(fptr->path); + } } static void @@ -4750,8 +4760,9 @@ rb_f_puts(int argc, VALUE *argv, VALUE recv) void rb_p(VALUE obj) /* for debug print within C code */ { - rb_io_write(rb_stdout, rb_obj_as_string(rb_inspect(obj))); - rb_io_write(rb_stdout, rb_default_rs); + VALUE str = rb_obj_as_string(rb_inspect(obj)); + rb_str_buf_append(str, rb_default_rs); + rb_io_write(rb_stdout, str); } /* -- cgit v1.2.3