From 69b20b190e5c1dca1a2d351c4d46c550c45b0610 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 16 Oct 2008 15:25:25 +0000 Subject: * io.c (rb_io_binmode): reset encoding conversion. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@19807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ io.c | 21 ++++++++++++++++----- test/ruby/test_io_m17n.rb | 13 ++++++++++++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd332b894..304c32592 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Oct 17 00:24:15 2008 Tanaka Akira + + * io.c (rb_io_binmode): reset encoding conversion. + Fri Oct 17 00:16:08 2008 Yusuke Endoh * io.c (rb_getc, rb_io_fread, rb_io_fwrite, rb_read_pending): diff --git a/io.c b/io.c index 89d8e7fc6..76b6f8771 100644 --- a/io.c +++ b/io.c @@ -3503,13 +3503,24 @@ rb_io_binmode(VALUE io) rb_io_t *fptr; GetOpenFile(io, fptr); - if (fptr->readconv) - rb_econv_binmode(fptr->readconv); - if (fptr->writeconv) - rb_econv_binmode(fptr->writeconv); + + if (fptr->readconv) { + rb_econv_close(fptr->readconv); + fptr->readconv = NULL; + } + if (fptr->writeconv) { + rb_econv_close(fptr->writeconv); + fptr->writeconv = NULL; + } fptr->mode |= FMODE_BINMODE; fptr->mode &= ~FMODE_TEXTMODE; - fptr->writeconv_pre_ecflags &= ~(ECONV_UNIVERSAL_NEWLINE_DECORATOR|ECONV_CRLF_NEWLINE_DECORATOR|ECONV_CR_NEWLINE_DECORATOR); + + fptr->encs.enc = rb_ascii8bit_encoding(); + fptr->encs.enc2 = NULL; + fptr->encs.ecflags = 0; + fptr->encs.ecopts = Qnil; + clear_codeconv(fptr); + return io; } diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index bff284660..eeec26d61 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -678,7 +678,6 @@ EOT def test_getc_invalid3 with_pipe("utf-16le:euc-jp") {|r, w| - w.binmode before1 = "\x42\x30".force_encoding("utf-16le") before2 = "\x44\x30".force_encoding("utf-16le") invalid = "\x00\xd8".force_encoding("utf-16le") @@ -1539,6 +1538,18 @@ EOT } end + def test_binmode3 + with_tmpdir { + src = "\u3042\r\n" + generate_file("t.txt", src) + srcbin = src.dup.force_encoding("ascii-8bit") + open("t.txt", "rt:utf-8:euc-jp") {|f| + f.binmode + assert_str_equal(srcbin, f.read) + } + } + end + def test_invalid_r with_tmpdir { generate_file("t.txt", "a\x80b") -- cgit