[Bug:trunk] confusion about treating filesystem encoding

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

e$B$V$i2<$2$I$3$m$,7h$a@Z$l$J$+$C$?e(B

e$B@hF|@.@%$5$s$,F~$l$F$/$@$5$C$?e(Bfilesystem
encodinge$BBP1~$G$9$,!"e(B
rb_encodinge$B$He(Bencoding indexe$B$r:.F1$7$F$$$^$9!#e(B
rb_encoding
e$B$NHf3S$,M-8z$J$N$+$I$&$+3N?.$,$J$+$C$?$N$G!"e(Bencoding
indexe$B$GE}0l$7$F$_$^$7$?!#e(B

rb_encoding*e$B$NHf3S$,M-8z$J$i$=$C$A$KB7$($?J}$,%7%s%W%k$K$Je(B

e$B$k$H$O;W$$$^$9!#e(B

rb_utf8_encindex()e$B$O$J$s$G$J$$$s$@$m$&e(B?

Index: io.c

— io.c (revision 17396)
+++ io.c (working copy)
@@ -4107,16 +4107,16 @@ rb_open_file(int argc, VALUE *argv, VALU
static int fs_encoding;
int fname_encoding = rb_enc_get_index(fname);
if (!fs_encoding)

  •  fs_encoding = rb_filesystem_encoding();
    
  • if (rb_usascii_encoding() != fname_encoding
  •  && rb_ascii8bit_encoding() != fname_encoding
    
  •  fs_encoding = rb_enc_to_index(rb_filesystem_encoding());
    
  • if (rb_usascii_encindex() != fname_encoding
  •  && rb_ascii8bit_encindex() != fname_encoding
    

#if defined APPLE

  •  && rb_utf8_encoding() != fname_encoding
    
  •  && rb_enc_to_index(rb_utf8_encoding()) != fname_encoding
    

#endif
&& fs_encoding != fname_encoding) {
static VALUE fs_enc;
if (!fs_enc)

  • fs_enc = rb_enc_from_encoding(fs_encoding);
  • fs_enc = rb_enc_from_encoding(rb_enc_from_index(fs_encoding));
    fname = rb_str_transcode(fname, fs_enc);
    }
    }

e$B$=$l$G$O!#e(B

e$B%A%1%C%He(B #179 e$B$,99?7$5$l$^$7$?!#e(B (by Yui NARUSE)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

Applied in changeset r17403.

http://redmine.ruby-lang.org/issues/show/179

e$B@.@%$G$9!#e(B

U.Nakamura wrote:

rb_utf8_encindex()e$B$O$J$s$G$J$$$s$@$m$&e(B?

e$B$=$&$$$($P$3$NM}M3$G$9$,!"C1$K8=;~E@$Ge(B UTF-8 e$B$Ne(B index
e$B$r07$&%3!<%I$,e(B
Ruby e$BK\BN$K$J$$$+$i$G$9!#e(B
e$B5U$K$$$($P!“e(BUS-ASCII e$B$de(B ASCII-8BIT e$B$,$”$k$N$O!“e(B
string.c e$B$H$+$G$=$&$$$&%3!<%I$,$”$k$+$i!#e(B