* io.c : add an extra byte to buffer for the specification of read

in Windows. see [ruby-core:33460] and r29980. and, we have to
	  discuss how to do this one byte.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tarui 2010-12-20 16:45:08 +00:00
parent 12b8ff1f46
commit da4d3e8464
2 changed files with 40 additions and 36 deletions

View File

@ -1,3 +1,9 @@
Tue Dec 21 01:41:42 2010 Masaya Tarui <tarui@ruby-lnag.org>
* io.c : add an extra byte to buffer for the specification of read
in Windows. see [ruby-core:33460] and r29980. and, we have to
discuss how to do this one byte.
Tue Dec 21 01:18:06 2010 KOSAKI Motohiro <kosaki.motohiro@gmail.com> Tue Dec 21 01:18:06 2010 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* error.c: Fix build error for win32. This regression was * error.c: Fix build error for win32. This regression was

70
io.c
View File

@ -1246,6 +1246,9 @@ io_fillbuf(rb_io_t *fptr)
fptr->rbuf.len = 0; fptr->rbuf.len = 0;
fptr->rbuf.capa = IO_RBUF_CAPA_FOR(fptr); fptr->rbuf.capa = IO_RBUF_CAPA_FOR(fptr);
fptr->rbuf.ptr = ALLOC_N(char, fptr->rbuf.capa); fptr->rbuf.ptr = ALLOC_N(char, fptr->rbuf.capa);
#ifdef _WIN32
fptr->rbuf.capa--;
#endif
} }
if (fptr->rbuf.len == 0) { if (fptr->rbuf.len == 0) {
retry: retry:
@ -1789,6 +1792,32 @@ io_shift_cbuf(rb_io_t *fptr, int len, VALUE *strp)
return str; return str;
} }
static void
io_setstrbuf(VALUE *str,long len)
{
#ifdef _WIN32
if (NIL_P(*str)) {
*str = rb_str_new(0, len+1);
rb_str_set_len(*str,len);
}
else {
StringValue(*str);
rb_str_modify(*str);
rb_str_resize(*str, len+1);
rb_str_set_len(*str,len);
}
#else
if (NIL_P(*str)) {
*str = rb_str_new(0, len);
}
else {
StringValue(*str);
rb_str_modify(*str);
rb_str_resize(*str, len);
}
#endif
}
static VALUE static VALUE
read_all(rb_io_t *fptr, long siz, VALUE str) read_all(rb_io_t *fptr, long siz, VALUE str)
{ {
@ -1799,8 +1828,7 @@ read_all(rb_io_t *fptr, long siz, VALUE str)
int cr; int cr;
if (NEED_READCONV(fptr)) { if (NEED_READCONV(fptr)) {
if (NIL_P(str)) str = rb_str_new(NULL, 0); io_setstrbuf(&str,0);
else rb_str_set_len(str, 0);
make_readconv(fptr, 0); make_readconv(fptr, 0);
while (1) { while (1) {
VALUE v; VALUE v;
@ -1828,12 +1856,7 @@ read_all(rb_io_t *fptr, long siz, VALUE str)
cr = 0; cr = 0;
if (siz == 0) siz = BUFSIZ; if (siz == 0) siz = BUFSIZ;
if (NIL_P(str)) { io_setstrbuf(&str,siz);
str = rb_str_new(0, siz);
}
else {
rb_str_resize(str, siz);
}
for (;;) { for (;;) {
READ_CHECK(fptr); READ_CHECK(fptr);
n = io_fread(str, bytes, fptr); n = io_fread(str, bytes, fptr);
@ -1886,14 +1909,7 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
rb_raise(rb_eArgError, "negative length %ld given", len); rb_raise(rb_eArgError, "negative length %ld given", len);
} }
if (NIL_P(str)) { io_setstrbuf(&str,len);
str = rb_str_new(0, len);
}
else {
StringValue(str);
rb_str_modify(str);
rb_str_resize(str, len);
}
OBJ_TAINT(str); OBJ_TAINT(str);
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
@ -2212,10 +2228,6 @@ io_read(int argc, VALUE *argv, VALUE io)
rb_scan_args(argc, argv, "02", &length, &str); rb_scan_args(argc, argv, "02", &length, &str);
if (NIL_P(length)) { if (NIL_P(length)) {
if (!NIL_P(str)){
StringValue(str);
rb_str_modify(str);
}
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
rb_io_check_char_readable(fptr); rb_io_check_char_readable(fptr);
return read_all(fptr, remain_size(fptr), str); return read_all(fptr, remain_size(fptr), str);
@ -2225,14 +2237,7 @@ io_read(int argc, VALUE *argv, VALUE io)
rb_raise(rb_eArgError, "negative length %ld given", len); rb_raise(rb_eArgError, "negative length %ld given", len);
} }
if (NIL_P(str)) { io_setstrbuf(&str,len);
str = rb_str_new(0, len);
}
else {
StringValue(str);
rb_str_modify(str);
rb_str_resize(str,len);
}
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
rb_io_check_byte_readable(fptr); rb_io_check_byte_readable(fptr);
@ -3941,14 +3946,7 @@ rb_io_sysread(int argc, VALUE *argv, VALUE io)
rb_scan_args(argc, argv, "11", &len, &str); rb_scan_args(argc, argv, "11", &len, &str);
ilen = NUM2LONG(len); ilen = NUM2LONG(len);
if (NIL_P(str)) { io_setstrbuf(&str,ilen);
str = rb_str_new(0, ilen);
}
else {
StringValue(str);
rb_str_modify(str);
rb_str_resize(str, ilen);
}
if (ilen == 0) return str; if (ilen == 0) return str;
GetOpenFile(io, fptr); GetOpenFile(io, fptr);