1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* io.c (make_readconv): now can specify the size of cbuf.

* io.c (read_all, appendline, io_getc, rb_io_ungetc): follow above
	  change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2008-10-28 11:18:28 +00:00
parent 2f4e4a841d
commit 7d934c47d1
2 changed files with 13 additions and 6 deletions

View file

@ -1,3 +1,10 @@
Tue Oct 28 20:15:49 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* io.c (make_readconv): now can specify the size of cbuf.
* io.c (read_all, appendline, io_getc, rb_io_ungetc): follow above
change.
Tue Oct 28 19:00:51 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_pipe_exec): internal fds should be always

12
io.c
View file

@ -1430,7 +1430,7 @@ io_enc_str(VALUE str, rb_io_t *fptr)
}
static void
make_readconv(rb_io_t *fptr)
make_readconv(rb_io_t *fptr, int size)
{
if (!fptr->readconv) {
int ecflags;
@ -1452,7 +1452,7 @@ make_readconv(rb_io_t *fptr)
rb_exc_raise(rb_econv_open_exc(sname, dname, ecflags));
fptr->cbuf_off = 0;
fptr->cbuf_len = 0;
fptr->cbuf_capa = 1024;
fptr->cbuf_capa = size < 1024 ? 1024 : size;
fptr->cbuf = ALLOC_N(char, fptr->cbuf_capa);
}
}
@ -1558,7 +1558,7 @@ read_all(rb_io_t *fptr, long siz, VALUE str)
if (NEED_READCONV(fptr)) {
if (NIL_P(str)) str = rb_str_new(NULL, 0);
else rb_str_set_len(str, 0);
make_readconv(fptr);
make_readconv(fptr, 0);
while (1) {
if (fptr->cbuf_len) {
io_shift_cbuf(fptr, fptr->cbuf_len, &str);
@ -1940,7 +1940,7 @@ appendline(rb_io_t *fptr, int delim, VALUE *strp, long *lp)
long limit = *lp;
if (NEED_READCONV(fptr)) {
make_readconv(fptr);
make_readconv(fptr, 0);
while (1) {
const char *p, *e;
int searchlen;
@ -2473,7 +2473,7 @@ io_getc(rb_io_t *fptr, rb_encoding *enc)
if (NEED_READCONV(fptr)) {
VALUE str = Qnil;
make_readconv(fptr);
make_readconv(fptr, 0);
while (1) {
if (fptr->cbuf_len) {
@ -2825,8 +2825,8 @@ rb_io_ungetc(VALUE io, VALUE c)
SafeStringValue(c);
}
if (NEED_READCONV(fptr)) {
make_readconv(fptr);
len = RSTRING_LEN(c);
make_readconv(fptr, len);
if (fptr->cbuf_capa - fptr->cbuf_len < len)
rb_raise(rb_eIOError, "ungetc failed");
if (fptr->cbuf_off < len) {