* eval.c (rb_thread_fd_close): raise for writing threads.
[ruby-dev:20269] * io.c (rb_io_close, io_reopen): ditto. * io.c (io_reopen): keep stdio objects for stdin, stdout, and stderr. [ruby-dev:19442] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1359207bf8
commit
874eca3c04
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
Thu May 22 02:42:49 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* eval.c (rb_thread_fd_close): raise for writing threads.
|
||||||
|
[ruby-dev:20269]
|
||||||
|
|
||||||
|
* io.c (rb_io_close, io_reopen): ditto.
|
||||||
|
|
||||||
|
* io.c (io_reopen): keep stdio objects for stdin, stdout,
|
||||||
|
and stderr. [ruby-dev:19442]
|
||||||
|
|
||||||
Thu May 22 01:11:15 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
Thu May 22 01:11:15 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
* parse.y (strings, word_list): must create new instance always.
|
* parse.y (strings, word_list): must create new instance always.
|
||||||
|
6
eval.c
6
eval.c
@ -8170,7 +8170,11 @@ rb_thread_fd_close(fd)
|
|||||||
rb_thread_t th;
|
rb_thread_t th;
|
||||||
|
|
||||||
FOREACH_THREAD(th) {
|
FOREACH_THREAD(th) {
|
||||||
if ((th->wait_for & WAIT_FD) && fd == th->fd) {
|
if (((th->wait_for & WAIT_FD) && fd == th->fd) ||
|
||||||
|
((th->wait_for & WAIT_SELECT) && (fd < th->fd) &&
|
||||||
|
(FD_ISSET(fd, &th->readfds) ||
|
||||||
|
FD_ISSET(fd, &th->writefds) ||
|
||||||
|
FD_ISSET(fd, &th->exceptfds)))) {
|
||||||
VALUE exc = rb_exc_new2(rb_eIOError, "stream closed");
|
VALUE exc = rb_exc_new2(rb_eIOError, "stream closed");
|
||||||
rb_thread_raise(1, &exc, th);
|
rb_thread_raise(1, &exc, th);
|
||||||
}
|
}
|
||||||
|
23
io.c
23
io.c
@ -1385,15 +1385,22 @@ rb_io_close(io)
|
|||||||
VALUE io;
|
VALUE io;
|
||||||
{
|
{
|
||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
int fd;
|
int fd, fd2;
|
||||||
|
|
||||||
fptr = RFILE(io)->fptr;
|
fptr = RFILE(io)->fptr;
|
||||||
if (!fptr) return Qnil;
|
if (!fptr) return Qnil;
|
||||||
if (!fptr->f && !fptr->f2) return Qnil;
|
if (fptr->f2) {
|
||||||
|
fd2 = fileno(fptr->f2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!fptr->f) return Qnil;
|
||||||
|
fd2 = -1;
|
||||||
|
}
|
||||||
|
|
||||||
fd = fileno(fptr->f);
|
fd = fileno(fptr->f);
|
||||||
rb_io_fptr_cleanup(fptr, Qfalse);
|
rb_io_fptr_cleanup(fptr, Qfalse);
|
||||||
rb_thread_fd_close(fd);
|
rb_thread_fd_close(fd);
|
||||||
|
if (fd2 >= 0) rb_thread_fd_close(fd2);
|
||||||
|
|
||||||
if (fptr->pid) {
|
if (fptr->pid) {
|
||||||
rb_syswait(fptr->pid);
|
rb_syswait(fptr->pid);
|
||||||
@ -1953,7 +1960,6 @@ pipe_del_fptr(fptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined (_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__VMS)
|
|
||||||
static void
|
static void
|
||||||
pipe_atexit _((void))
|
pipe_atexit _((void))
|
||||||
{
|
{
|
||||||
@ -1966,7 +1972,6 @@ pipe_atexit _((void))
|
|||||||
list = tmp;
|
list = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static void pipe_finalize _((OpenFile *fptr,int));
|
static void pipe_finalize _((OpenFile *fptr,int));
|
||||||
|
|
||||||
@ -2351,7 +2356,9 @@ io_reopen(io, nfile)
|
|||||||
else if (orig->mode & FMODE_WRITABLE) {
|
else if (orig->mode & FMODE_WRITABLE) {
|
||||||
io_fflush(orig->f, orig);
|
io_fflush(orig->f, orig);
|
||||||
}
|
}
|
||||||
rb_thread_fd_close(fileno(fptr->f));
|
if (fptr->mode & FMODE_WRITABLE) {
|
||||||
|
io_fflush(GetWriteFile(fptr), fptr);
|
||||||
|
}
|
||||||
|
|
||||||
/* copy OpenFile structure */
|
/* copy OpenFile structure */
|
||||||
fptr->mode = orig->mode;
|
fptr->mode = orig->mode;
|
||||||
@ -2364,7 +2371,7 @@ io_reopen(io, nfile)
|
|||||||
|
|
||||||
mode = rb_io_mode_string(fptr);
|
mode = rb_io_mode_string(fptr);
|
||||||
fd = fileno(fptr->f);
|
fd = fileno(fptr->f);
|
||||||
if (fd < 3) {
|
if (fd == fileno(stdin) || fd == fileno(stdout) || fd == fileno(stderr)) {
|
||||||
clearerr(fptr->f);
|
clearerr(fptr->f);
|
||||||
/* need to keep stdio objects */
|
/* need to keep stdio objects */
|
||||||
if (dup2(fileno(orig->f), fd) < 0)
|
if (dup2(fileno(orig->f), fd) < 0)
|
||||||
@ -2376,14 +2383,16 @@ io_reopen(io, nfile)
|
|||||||
rb_sys_fail(orig->path);
|
rb_sys_fail(orig->path);
|
||||||
fptr->f = rb_fdopen(fd, mode);
|
fptr->f = rb_fdopen(fd, mode);
|
||||||
}
|
}
|
||||||
|
rb_thread_fd_close(fd);
|
||||||
if ((orig->mode & FMODE_READABLE) && pos >= 0) {
|
if ((orig->mode & FMODE_READABLE) && pos >= 0) {
|
||||||
io_seek(fptr, pos, SEEK_SET);
|
io_seek(fptr, pos, SEEK_SET);
|
||||||
io_seek(orig, pos, SEEK_SET);
|
io_seek(orig, pos, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fptr->f2) {
|
if (fptr->f2 && fd != fileno(fptr->f2)) {
|
||||||
fd = fileno(fptr->f2);
|
fd = fileno(fptr->f2);
|
||||||
fclose(fptr->f2);
|
fclose(fptr->f2);
|
||||||
|
rb_thread_fd_close(fd);
|
||||||
if (orig->f2) {
|
if (orig->f2) {
|
||||||
if (dup2(fileno(orig->f2), fd) < 0)
|
if (dup2(fileno(orig->f2), fd) < 0)
|
||||||
rb_sys_fail(orig->path);
|
rb_sys_fail(orig->path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user