ruby-changes:8279
From: akr <ko1@a...>
Date: Fri, 17 Oct 2008 00:32:06 +0900 (JST)
Subject: [ruby-changes:8279] Ruby:r19807 (trunk): * io.c (rb_io_binmode): reset encoding conversion.
akr 2008-10-17 00:25:25 +0900 (Fri, 17 Oct 2008) New Revision: 19807 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19807 Log: * io.c (rb_io_binmode): reset encoding conversion. Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io_m17n.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 19806) +++ ChangeLog (revision 19807) @@ -1,3 +1,7 @@ +Fri Oct 17 00:24:15 2008 Tanaka Akira <akr@f...> + + * io.c (rb_io_binmode): reset encoding conversion. + Fri Oct 17 00:16:08 2008 Yusuke Endoh <mame@t...> * io.c (rb_getc, rb_io_fread, rb_io_fwrite, rb_read_pending): Index: io.c =================================================================== --- io.c (revision 19806) +++ io.c (revision 19807) @@ -3503,13 +3503,24 @@ 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; } Index: test/ruby/test_io_m17n.rb =================================================================== --- test/ruby/test_io_m17n.rb (revision 19806) +++ test/ruby/test_io_m17n.rb (revision 19807) @@ -678,7 +678,6 @@ 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 @@ } 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") -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/