summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-20 16:57:19 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-20 16:57:19 +0000
commite50a5bcef093f814ebd8d162a3c2f3665620e412 (patch)
treec416336a18a6390642bbfa72b9d0aecde06e2dc3 /io.c
parentb5e583f7e39b45c6fbdadafcf8d9dc76ff13eefc (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/io.c b/io.c
index 3795fb76dc..29b98d0bac 100644
--- a/io.c
+++ b/io.c
@@ -669,7 +669,7 @@ rb_io_wait_writable(int f)
# 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 @@ make_writeconv(rb_io_t *fptr)
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 @@ do_writeconv(VALUE str, rb_io_t *fptr)
{
if (NEED_WRITECONV(fptr)) {
VALUE common_encoding = Qnil;
+
make_writeconv(fptr);
if (fptr->writeconv) {
@@ -817,7 +818,7 @@ do_writeconv(VALUE str, rb_io_t *fptr)
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 @@ rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash,
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 @@ rb_file_open_internal(VALUE io, VALUE filename, const char *modestr)
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;
}