* io.c (rb_io_check_readable): should not fill fptr->enc always.
read-write IO (e.g. socket) does not work. [ruby-dev:32685] * io.c (io_read_encoding): retrieve reading encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5f9748deb7
commit
7ea8ec5483
@ -1,3 +1,10 @@
|
|||||||
|
Mon Dec 24 02:59:32 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (rb_io_check_readable): should not fill fptr->enc always.
|
||||||
|
read-write IO (e.g. socket) does not work. [ruby-dev:32685]
|
||||||
|
|
||||||
|
* io.c (io_read_encoding): retrieve reading encoding.
|
||||||
|
|
||||||
Mon Dec 24 02:06:35 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Mon Dec 24 02:06:35 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (rb_f_open): documentation update.
|
* io.c (rb_f_open): documentation update.
|
||||||
|
27
io.c
27
io.c
@ -347,12 +347,21 @@ rb_io_check_readable(rb_io_t *fptr)
|
|||||||
if (fptr->wbuf_len) {
|
if (fptr->wbuf_len) {
|
||||||
io_fflush(fptr);
|
io_fflush(fptr);
|
||||||
}
|
}
|
||||||
if (!fptr->enc) {
|
if (!fptr->enc && fptr->fd == 0) {
|
||||||
fptr->enc = (fptr->mode & FMODE_BINMODE)
|
fptr->enc = rb_default_external_encoding();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static rb_encoding*
|
||||||
|
io_read_encoding(rb_io_t *fptr)
|
||||||
|
{
|
||||||
|
if (fptr->enc) {
|
||||||
|
return fptr->enc;
|
||||||
|
}
|
||||||
|
return (fptr->mode & FMODE_BINMODE)
|
||||||
? rb_ascii8bit_encoding()
|
? rb_ascii8bit_encoding()
|
||||||
: rb_default_external_encoding();
|
: rb_default_external_encoding();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_io_check_writable(rb_io_t *fptr)
|
rb_io_check_writable(rb_io_t *fptr)
|
||||||
@ -1307,7 +1316,7 @@ io_enc_str(VALUE str, rb_io_t *fptr)
|
|||||||
rb_enc_from_encoding(fptr->enc),
|
rb_enc_from_encoding(fptr->enc),
|
||||||
rb_enc_from_encoding(fptr->enc2));
|
rb_enc_from_encoding(fptr->enc2));
|
||||||
}
|
}
|
||||||
else {
|
else if (fptr->enc) {
|
||||||
/* just one encoding, so associate it with the string */
|
/* just one encoding, so associate it with the string */
|
||||||
rb_enc_associate(str, fptr->enc);
|
rb_enc_associate(str, fptr->enc);
|
||||||
}
|
}
|
||||||
@ -1800,7 +1809,7 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
|
|||||||
if (RSTRING_LEN(str) == 0) return Qnil;
|
if (RSTRING_LEN(str) == 0) return Qnil;
|
||||||
}
|
}
|
||||||
else if (limit == 0) {
|
else if (limit == 0) {
|
||||||
return rb_enc_str_new(0, 0, fptr->enc);
|
return rb_enc_str_new(0, 0, io_read_encoding(fptr));
|
||||||
}
|
}
|
||||||
else if (rs == rb_default_rs) {
|
else if (rs == rb_default_rs) {
|
||||||
return rb_io_getline_fast(fptr, '\n', limit);
|
return rb_io_getline_fast(fptr, '\n', limit);
|
||||||
@ -2175,7 +2184,7 @@ rb_io_getc(VALUE io)
|
|||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_readable(fptr);
|
rb_io_check_readable(fptr);
|
||||||
|
|
||||||
enc = fptr->enc;
|
enc = io_read_encoding(fptr);
|
||||||
READ_CHECK(fptr);
|
READ_CHECK(fptr);
|
||||||
if (io_fillbuf(fptr) < 0) {
|
if (io_fillbuf(fptr) < 0) {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
@ -2327,7 +2336,7 @@ rb_io_ungetc(VALUE io, VALUE c)
|
|||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_readable(fptr);
|
rb_io_check_readable(fptr);
|
||||||
if (NIL_P(c)) return Qnil;
|
if (NIL_P(c)) return Qnil;
|
||||||
enc = fptr->enc;
|
enc = io_read_encoding(fptr);
|
||||||
if (FIXNUM_P(c)) {
|
if (FIXNUM_P(c)) {
|
||||||
int cc = FIX2INT(c);
|
int cc = FIX2INT(c);
|
||||||
char buf[16];
|
char buf[16];
|
||||||
@ -5854,7 +5863,7 @@ rb_io_external_encoding(VALUE io)
|
|||||||
if (!fptr->enc && fptr->fd == 0) {
|
if (!fptr->enc && fptr->fd == 0) {
|
||||||
fptr->enc = rb_default_external_encoding();
|
fptr->enc = rb_default_external_encoding();
|
||||||
}
|
}
|
||||||
return rb_enc_from_encoding(fptr->enc);
|
return rb_enc_from_encoding(io_read_encoding(fptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -5872,7 +5881,7 @@ rb_io_internal_encoding(VALUE io)
|
|||||||
|
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
if (!fptr->enc2) return Qnil;
|
if (!fptr->enc2) return Qnil;
|
||||||
return rb_enc_from_encoding(fptr->enc);
|
return rb_enc_from_encoding(io_read_encoding(fptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user