ruby-changes:13469
From: akr <ko1@a...>
Date: Tue, 6 Oct 2009 21:32:10 +0900 (JST)
Subject: [ruby-changes:13469] Ruby:r25244 (trunk): * io.c (io_reopen): avoid close if possible.
akr 2009-10-06 21:31:53 +0900 (Tue, 06 Oct 2009) New Revision: 25244 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25244 Log: * io.c (io_reopen): avoid close if possible. Modified files: trunk/ChangeLog trunk/io.c Index: ChangeLog =================================================================== --- ChangeLog (revision 25243) +++ ChangeLog (revision 25244) @@ -1,3 +1,7 @@ +Tue Oct 6 21:30:58 2009 Tanaka Akira <akr@f...> + + * io.c (io_reopen): avoid close if possible. + Tue Oct 6 18:56:09 2009 Yukihiro Matsumoto <matz@r...> * struct.c (rb_struct_select): Struct#select should return Index: io.c =================================================================== --- io.c (revision 25243) +++ io.c (revision 25244) @@ -5684,20 +5684,17 @@ fd = fptr->fd; fd2 = orig->fd; if (fd != fd2) { - if (IS_PREP_STDIO(fptr)) { - /* need to keep stdio objects */ + if (IS_PREP_STDIO(fptr) || fd <= 2 || !fptr->stdio_file) { + /* need to keep FILE objects of stdin, stdout and stderr */ if (dup2(fd2, fd) < 0) rb_sys_fail_path(orig->pathv); } else { - if (fptr->stdio_file) - fclose(fptr->stdio_file); - else - close(fptr->fd); + fclose(fptr->stdio_file); fptr->stdio_file = 0; fptr->fd = -1; - if (dup2(fd2, fd) < 0) - rb_sys_fail_path(orig->pathv); + if (dup2(fd2, fd) < 0) + rb_sys_fail_path(orig->pathv); fptr->fd = fd; } rb_thread_fd_close(fd); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/