From e8a71bc8539a71a836036ba9df195b06638c196f Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 22 Dec 2007 17:28:20 +0000 Subject: * io.c (rb_io_mode_enc): do not set encoding unless explicitly specified. * io.c (rb_io_check_readable): fill fptr->enc by default_external if it's empty. * io.c (io_enc_str): fptr->enc is always set for reading IO (by rb_io_check_readable(fptr)). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 7bfe9a14c3..b1521a1e17 100644 --- a/io.c +++ b/io.c @@ -347,8 +347,10 @@ rb_io_check_readable(rb_io_t *fptr) if (fptr->wbuf_len) { io_fflush(fptr); } - if (!fptr->enc && fptr->fd == 0) { - fptr->enc = rb_default_external_encoding(); + if (!fptr->enc) { + fptr->enc = (fptr->fd == 0) + ? rb_default_external_encoding() + : rb_ascii_encoding(); } } @@ -627,7 +629,7 @@ io_fwrite(VALUE str, rb_io_t *fptr) * the strings encoding then we must transcode before writing. * We must also transcode if two encodings were specified */ - if (fptr->enc && (fptr->enc2 || fptr->enc != rb_enc_get(str))) { + if (fptr->enc) { /* transcode str before output */ /* the methods in transcode.c are static, so call indirectly */ /* Can't use encode! because puts writes a frozen newline */ @@ -1298,18 +1300,16 @@ static VALUE io_enc_str(VALUE str, rb_io_t *fptr) { OBJ_TAINT(str); - if (fptr->enc) { - if (fptr->enc2) { - /* two encodings, so transcode from enc2 to enc */ - /* the methods in transcode.c are static, so call indirectly */ - str = rb_funcall(str, id_encode, 2, - rb_enc_from_encoding(fptr->enc2), - rb_enc_from_encoding(fptr->enc)); - } - else { - /* just one encoding, so associate it with the string */ - rb_enc_associate(str, fptr->enc); - } + if (fptr->enc2) { + /* two encodings, so transcode from enc2 to enc */ + /* the methods in transcode.c are static, so call indirectly */ + str = rb_funcall(str, id_encode, 2, + rb_enc_from_encoding(fptr->enc2), + rb_enc_from_encoding(fptr->enc)); + } + else { + /* just one encoding, so associate it with the string */ + rb_enc_associate(str, fptr->enc); } return str; } @@ -2175,7 +2175,7 @@ rb_io_getc(VALUE io) GetOpenFile(io, fptr); rb_io_check_readable(fptr); - enc = fptr->enc ? fptr->enc : rb_default_external_encoding(); + enc = fptr->enc; READ_CHECK(fptr); if (io_fillbuf(fptr) < 0) { return Qnil; @@ -2327,7 +2327,7 @@ rb_io_ungetc(VALUE io, VALUE c) GetOpenFile(io, fptr); rb_io_check_readable(fptr); if (NIL_P(c)) return Qnil; - enc = fptr->enc ? fptr->enc : rb_default_external_encoding(); + enc = fptr->enc; if (FIXNUM_P(c)) { int cc = FIX2INT(c); char buf[16]; @@ -3123,12 +3123,6 @@ rb_io_mode_enc(rb_io_t *fptr, const char *mode) } } } - else if (fptr->mode & FMODE_BINMODE) { - fptr->enc = rb_ascii_encoding(); - } - else { - fptr->enc = rb_default_external_encoding(); - } } struct sysopen_struct { -- cgit v1.2.3