Skip to content

Commit

Permalink
revert my previous commit (d5d1e6f). because IO#read is broken after …
Browse files Browse the repository at this point in the history
…calling IO#ungetc.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

r, w = IO.pipe
w.write "foobar"
w.close

c = r.read(1)
r.ungetc(c)
assert_equal("foo", r.read(3))
assert_equal("bar", r.read(3))
r.close

puts :ok
}}}
  • Loading branch information
Watson1978 committed Jun 2, 2011
1 parent f1ef1ff commit 814de01
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions io.c
Expand Up @@ -1069,13 +1069,7 @@ rb_io_read_all(rb_io_t *io_struct, VALUE outbuf)
while (true) {
rb_bstr_resize(outbuf, original_position + bytes_read + bufsize);
uint8_t *bytes = rb_bstr_bytes(outbuf) + original_position + bytes_read;
long last_read;
if (io_struct->buf != NULL) {
last_read = rb_io_read_internal(io_struct, bytes, bufsize);
}
else {
last_read = read_internal(io_struct->read_fd, (UInt8 *)bytes, bufsize);
}
const long last_read = rb_io_read_internal(io_struct, bytes, bufsize);
bytes_read += last_read;
if (last_read == 0) {
break;
Expand Down Expand Up @@ -1347,14 +1341,7 @@ io_read(VALUE io, SEL sel, int argc, VALUE *argv)
rb_bstr_resize(outbuf, size);
uint8_t *bytes = rb_bstr_bytes(outbuf);

long data_read;
if (io_struct->buf != NULL) {
data_read = rb_io_read_internal(io_struct, bytes, size);
}
else {
data_read = read_internal(io_struct->read_fd, (UInt8 *)bytes, size);
}

const long data_read = rb_io_read_internal(io_struct, bytes, size);
rb_bstr_set_length(outbuf, data_read);

if (data_read == 0) {
Expand Down

0 comments on commit 814de01

Please sign in to comment.