Skip to content

Commit

Permalink
ext/io/wait: needs variable which was allocated by xmalloc when invok…
Browse files Browse the repository at this point in the history
…e rb_fd_init.
  • Loading branch information
Watson1978 committed Dec 9, 2011
1 parent f6de7df commit ec5096a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions ext/io/wait/wait.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static VALUE
io_wait(int argc, VALUE *argv, VALUE io) io_wait(int argc, VALUE *argv, VALUE io)
{ {
rb_io_t *fptr; rb_io_t *fptr;
struct wait_readable_arg arg; struct wait_readable_arg *arg;
int fd, i; int fd, i;
ioctl_arg n; ioctl_arg n;
VALUE timeout; VALUE timeout;
Expand All @@ -128,24 +128,25 @@ io_wait(int argc, VALUE *argv, VALUE io)
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
rb_io_check_readable(fptr); rb_io_check_readable(fptr);
rb_scan_args(argc, argv, "01", &timeout); rb_scan_args(argc, argv, "01", &timeout);
arg = (struct wait_readable_arg *)xmalloc(sizeof(struct wait_readable_arg));
if (NIL_P(timeout)) { if (NIL_P(timeout)) {
arg.timeout = 0; arg->timeout = 0;
} }
else { else {
timerec = rb_time_interval(timeout); timerec = rb_time_interval(timeout);
arg.timeout = &timerec; arg->timeout = &timerec;
} }


if (rb_io_read_pending(fptr)) return Qtrue; if (rb_io_read_pending(fptr)) return Qtrue;
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse; if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse;
fd = fptr->fd; fd = fptr->fd;
rb_fd_init(&arg.fds); rb_fd_init(&arg->fds);
rb_fd_set(fd, &arg.fds); rb_fd_set(fd, &arg->fds);
#ifdef HAVE_RB_FD_INIT #ifdef HAVE_RB_FD_INIT
i = (int)rb_ensure(wait_readable, (VALUE)&arg, i = (int)rb_ensure(wait_readable, (VALUE)arg,
(VALUE (*)_((VALUE)))rb_fd_term, (VALUE)&arg.fds); (VALUE (*)_((VALUE)))rb_fd_term, (VALUE)&arg->fds);
#else #else
i = rb_thread_select(fd + 1, rb_fd_ptr(&arg.fds), NULL, NULL, arg.timeout); i = rb_thread_select(fd + 1, rb_fd_ptr(&arg->fds), NULL, NULL, arg->timeout);
#endif #endif
if (i < 0) if (i < 0)
rb_sys_fail(0); rb_sys_fail(0);
Expand Down

0 comments on commit ec5096a

Please sign in to comment.