[前][次][番号順一覧][スレッド一覧]

ruby-changes:8334

From: matz <ko1@a...>
Date: Tue, 21 Oct 2008 01:57:40 +0900 (JST)
Subject: [ruby-changes:8334] Ruby:r19862 (trunk): * io.c (rb_io_extract_modeenc): plain rb/wb should set ASCII-8BIT

matz	2008-10-21 01:57:19 +0900 (Tue, 21 Oct 2008)

  New Revision: 19862

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19862

  Log:
    * io.c (rb_io_extract_modeenc): plain rb/wb should set ASCII-8BIT
      to the external_encoding.
    
    * io.c (rb_file_open_internal): ditto.
    
    * io.c (NEED_WRITECONV): no conversion when the external_encoding
      is ASCII-8BIT.
    
    * io.c (do_writeconv): skip ASCII-8BIT.

  Modified files:
    trunk/ChangeLog
    trunk/io.c
    trunk/test/ruby/test_io_m17n.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19861)
+++ ChangeLog	(revision 19862)
@@ -1,3 +1,15 @@
+Tue Oct 21 01:49:55 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* io.c (rb_io_extract_modeenc): plain rb/wb should set ASCII-8BIT
+	  to the external_encoding.
+
+	* io.c (rb_file_open_internal): ditto.
+
+	* io.c (NEED_WRITECONV): no conversion when the external_encoding
+	  is ASCII-8BIT.
+
+	* io.c (do_writeconv): skip ASCII-8BIT.
+
 Tue Oct 21 00:51:59 2008  Tanaka Akira  <akr@f...>
 
 	* io.c (rb_io_ascii8bit_binmode): renamed from rb_io_binmode.
Index: io.c
===================================================================
--- io.c	(revision 19861)
+++ io.c	(revision 19862)
@@ -669,7 +669,7 @@
 # define NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) 0
 #endif
 #define NEED_READCONV(fptr) (fptr->encs.enc2 != NULL || NEED_NEWLINE_DECORATOR_ON_READ(fptr))
-#define NEED_WRITECONV(fptr) (fptr->encs.enc != NULL || NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) || (fptr->encs.ecflags & (ECONV_DECORATOR_MASK|ECONV_STATEFUL_DECORATOR_MASK)))
+#define NEED_WRITECONV(fptr) ((fptr->encs.enc != NULL && fptr->encs.enc != rb_ascii8bit_encoding()) || NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) || (fptr->encs.ecflags & (ECONV_DECORATOR_MASK|ECONV_STATEFUL_DECORATOR_MASK)))
 
 static void
 make_writeconv(rb_io_t *fptr)
@@ -689,7 +689,7 @@
             ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
 #endif
 
-        if (!fptr->encs.enc) {
+        if (!fptr->encs.enc || (fptr->encs.enc == rb_ascii8bit_encoding() && !fptr->encs.enc2)) {
             /* no encoding conversion */
             fptr->writeconv_pre_ecflags = 0;
             fptr->writeconv_pre_ecopts = Qnil;
@@ -804,6 +804,7 @@
 {
     if (NEED_WRITECONV(fptr)) {
         VALUE common_encoding = Qnil;
+
         make_writeconv(fptr);
 
         if (fptr->writeconv) {
@@ -817,7 +818,7 @@
         else {
             if (fptr->encs.enc2)
                 common_encoding = rb_enc_from_encoding(fptr->encs.enc2);
-            else
+            else if (fptr->encs.enc != rb_ascii8bit_encoding())
                 common_encoding = rb_enc_from_encoding(fptr->encs.enc);
         }
 
@@ -3959,6 +3960,12 @@
             has_enc = 1;
             parse_mode_enc(p+1, &enc, &enc2);
         }
+	else {
+	    rb_encoding *e;
+
+	    e = (fmode & FMODE_BINMODE) ? rb_ascii8bit_encoding() : NULL;
+	    rb_io_ext_int_to_encs(e, NULL, &enc, &enc2);
+	}
     }
 
     if (NIL_P(opthash)) {
@@ -4151,8 +4158,11 @@
         parse_mode_enc(p+1, &convconfig.enc, &convconfig.enc2);
     }
     else {
+	rb_encoding *e;
 	/* Set to default encodings */
-	rb_io_ext_int_to_encs(NULL, NULL, &convconfig.enc, &convconfig.enc2);
+
+	e = (fmode & FMODE_BINMODE) ? rb_ascii8bit_encoding() : NULL;
+	rb_io_ext_int_to_encs(e, NULL, &convconfig.enc, &convconfig.enc2);
         convconfig.ecflags = 0;
         convconfig.ecopts = Qnil;
     }
Index: test/ruby/test_io_m17n.rb
===================================================================
--- test/ruby/test_io_m17n.rb	(revision 19861)
+++ test/ruby/test_io_m17n.rb	(revision 19862)
@@ -59,7 +59,7 @@
     with_tmpdir {
       generate_file('tmp', "")
       open("tmp", "rb") {|f|
-        assert_equal(Encoding.default_external, f.external_encoding)
+        assert_equal(Encoding.find("ASCII-8BIT"), f.external_encoding)
         assert_equal(nil, f.internal_encoding)
       }
     }
@@ -137,7 +137,7 @@
   def test_open_wb
     with_tmpdir {
       open("tmp", "wb") {|f|
-        assert_equal(nil, f.external_encoding)
+        assert_equal(Encoding.find("ASCII-8BIT"), f.external_encoding)
         assert_equal(nil, f.internal_encoding)
       }
     }
@@ -1314,7 +1314,7 @@
       #   0xA1F1        0xC2A2          U+00A2
 
       open("t","rt") {|f| assert_equal("a\nb\nc\n\xc2\xa2".force_encoding(Encoding.default_external), f.read) }
-      open("t","rb") {|f| assert_equal("a\rb\r\nc\n\xc2\xa2".force_encoding(Encoding.default_external), f.read) }
+      open("t","rb") {|f| assert_equal("a\rb\r\nc\n\xc2\xa2".force_encoding(Encoding::ASCII_8BIT), f.read) }
 
       open("t","rt:euc-jp") {|f| assert_equal("a\nb\nc\n\xc2\xa2".force_encoding("EUC-JP"), f.read) }
       open("t","rb:euc-jp") {|f| assert_equal("a\rb\r\nc\n\xc2\xa2".force_encoding("EUC-JP"), f.read) }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]