Skip to content

Commit

Permalink
* eval.c (rb_thread_fd_close): raise for writing threads.
Browse files Browse the repository at this point in the history
  [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
  • Loading branch information
nobu committed May 21, 2003
1 parent 1359207 commit 874eca3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Thu May 22 02:42:49 2003 Nobuyoshi Nakada <[email protected]>

* 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 <[email protected]>

* parse.y (strings, word_list): must create new instance always.
Expand Down
6 changes: 5 additions & 1 deletion eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -8170,7 +8170,11 @@ rb_thread_fd_close(fd)
rb_thread_t 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");
rb_thread_raise(1, &exc, th);
}
Expand Down
25 changes: 17 additions & 8 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ rb_io_fread(ptr, len, f)
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EWOULDBLOCK:
#endif
if (len - n >= 0) {
if (len - n >= 0) {
clearerr(f);
return len - n;
}
Expand Down Expand Up @@ -1385,15 +1385,22 @@ rb_io_close(io)
VALUE io;
{
OpenFile *fptr;
int fd;
int fd, fd2;

fptr = RFILE(io)->fptr;
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);
rb_io_fptr_cleanup(fptr, Qfalse);
rb_thread_fd_close(fd);
if (fd2 >= 0) rb_thread_fd_close(fd2);

if (fptr->pid) {
rb_syswait(fptr->pid);
Expand Down Expand Up @@ -1953,7 +1960,6 @@ pipe_del_fptr(fptr)
}
}

#if defined (_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__VMS)
static void
pipe_atexit _((void))
{
Expand All @@ -1966,7 +1972,6 @@ pipe_atexit _((void))
list = tmp;
}
}
#endif

static void pipe_finalize _((OpenFile *fptr,int));

Expand Down Expand Up @@ -2351,7 +2356,9 @@ io_reopen(io, nfile)
else if (orig->mode & FMODE_WRITABLE) {
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 */
fptr->mode = orig->mode;
Expand All @@ -2364,7 +2371,7 @@ io_reopen(io, nfile)

mode = rb_io_mode_string(fptr);
fd = fileno(fptr->f);
if (fd < 3) {
if (fd == fileno(stdin) || fd == fileno(stdout) || fd == fileno(stderr)) {
clearerr(fptr->f);
/* need to keep stdio objects */
if (dup2(fileno(orig->f), fd) < 0)
Expand All @@ -2376,14 +2383,16 @@ io_reopen(io, nfile)
rb_sys_fail(orig->path);
fptr->f = rb_fdopen(fd, mode);
}
rb_thread_fd_close(fd);
if ((orig->mode & FMODE_READABLE) && pos >= 0) {
io_seek(fptr, pos, SEEK_SET);
io_seek(orig, pos, SEEK_SET);
}

if (fptr->f2) {
if (fptr->f2 && fd != fileno(fptr->f2)) {
fd = fileno(fptr->f2);
fclose(fptr->f2);
rb_thread_fd_close(fd);
if (orig->f2) {
if (dup2(fileno(orig->f2), fd) < 0)
rb_sys_fail(orig->path);
Expand Down

0 comments on commit 874eca3

Please sign in to comment.