Skip to content

Commit

Permalink
sync potential bytestrings
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@573 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed Sep 8, 2008
1 parent f6ee6c8 commit 00768a6
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions io.c
Expand Up @@ -712,7 +712,10 @@ io_fwrite(VALUE str, rb_io_t *fptr)
}

len = RSTRING_BYTELEN(str);
if ((n = len) <= 0) return n;
if ((n = len) <= 0) {
RSTRING_SYNC(str);
return n;
}
if (fptr->wbuf == NULL && !(fptr->mode & FMODE_SYNC)) {
fptr->wbuf_off = 0;
fptr->wbuf_len = 0;
Expand All @@ -731,10 +734,14 @@ io_fwrite(VALUE str, rb_io_t *fptr)
fptr->wbuf_len += len;
n = 0;
}
if (io_fflush(fptr) < 0)
if (io_fflush(fptr) < 0) {
RSTRING_SYNC(str);
return -1L;
if (n == 0)
}
if (n == 0) {
RSTRING_SYNC(str);
return len;
}
/* avoid context switch between "a" and "\n" in STDERR.puts "a".
[ruby-dev:25080] */
if (fptr->stdio_file != stderr && !rb_thread_fd_writable(fptr->fd)) {
Expand All @@ -750,7 +757,10 @@ io_fwrite(VALUE str, rb_io_t *fptr)
}
r = rb_write_internal(fptr->fd, RSTRING_BYTEPTR(str)+offset, l);
/* xxx: other threads may modify given string. */
if (r == n) return len;
if (r == n) {
RSTRING_SYNC(str);
return len;
}
if (0 <= r) {
offset += r;
n -= r;
Expand All @@ -761,6 +771,7 @@ io_fwrite(VALUE str, rb_io_t *fptr)
if (offset < RSTRING_BYTELEN(str))
goto retry;
}
RSTRING_SYNC(str);
return -1L;
}

Expand All @@ -771,6 +782,7 @@ io_fwrite(VALUE str, rb_io_t *fptr)
}
MEMMOVE(fptr->wbuf+fptr->wbuf_off+fptr->wbuf_len, RSTRING_BYTEPTR(str)+offset, char, len);
fptr->wbuf_len += len;
RSTRING_SYNC(str);
return len;
}

Expand Down Expand Up @@ -4821,6 +4833,7 @@ rb_io_puts(int argc, VALUE *argv, VALUE out)
RSTRING_BYTEPTR(line)[RSTRING_BYTELEN(line)-1] != '\n') {
rb_io_write(out, rb_default_rs);
}
RSTRING_SYNC(line);
}

return Qnil;
Expand Down

0 comments on commit 00768a6

Please sign in to comment.