* 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
This commit is contained in:
akr 2008-06-09 08:48:41 +00:00
parent 3854be4322
commit 507f89d33f
2 changed files with 20 additions and 4 deletions

View File

@ -1,3 +1,8 @@
Mon Jun 9 17:47:09 2008 Tanaka Akira <akr@fsij.org>
* io.c (fptr_finalize): close IO object if fd is already closed.
(rb_p): call rb_io_write just once.
Mon Jun 9 15:37:38 2008 Yukihiro Matsumoto <matz@ruby-lang.org> Mon Jun 9 15:37:38 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* ruby.c (require_libraries): req_list may be NULL. [ruby-dev:35008] * ruby.c (require_libraries): req_list may be NULL. [ruby-dev:35008]

15
io.c
View File

@ -2673,6 +2673,7 @@ rb_io_set_close_on_exec(VALUE io, VALUE arg)
static void static void
fptr_finalize(rb_io_t *fptr, int noraise) fptr_finalize(rb_io_t *fptr, int noraise)
{ {
int ebadf = 0;
if (fptr->wbuf_len) { if (fptr->wbuf_len) {
io_fflush(fptr); io_fflush(fptr);
} }
@ -2690,13 +2691,22 @@ fptr_finalize(rb_io_t *fptr, int noraise)
} }
else if (0 <= fptr->fd) { else if (0 <= fptr->fd) {
if (close(fptr->fd) < 0 && !noraise) { if (close(fptr->fd) < 0 && !noraise) {
if (errno != EBADF) {
/* fptr->fd is still not closed */ /* fptr->fd is still not closed */
rb_sys_fail(fptr->path); rb_sys_fail(fptr->path);
} }
else {
/* fptr->fd is already closed. */
ebadf = 1;
}
}
} }
fptr->fd = -1; fptr->fd = -1;
fptr->stdio_file = 0; fptr->stdio_file = 0;
fptr->mode &= ~(FMODE_READABLE|FMODE_WRITABLE); fptr->mode &= ~(FMODE_READABLE|FMODE_WRITABLE);
if (ebadf) {
rb_sys_fail(fptr->path);
}
} }
static void static void
@ -4750,8 +4760,9 @@ rb_f_puts(int argc, VALUE *argv, VALUE recv)
void void
rb_p(VALUE obj) /* for debug print within C code */ rb_p(VALUE obj) /* for debug print within C code */
{ {
rb_io_write(rb_stdout, rb_obj_as_string(rb_inspect(obj))); VALUE str = rb_obj_as_string(rb_inspect(obj));
rb_io_write(rb_stdout, rb_default_rs); rb_str_buf_append(str, rb_default_rs);
rb_io_write(rb_stdout, str);
} }
/* /*