summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-13 09:49:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-13 09:49:25 +0000
commitadd73a87136653409abd0df39e2f2a8ec50a0cf7 (patch)
tree3df564064ec85b577b83881117ffb73055d8e7d4
parentb861d5473cfa1f3aa64979d9ff0655230eea9a14 (diff)
io.c: encoding in warnings
* io.c (parse_mode_enc): preserve encoding of mode string in warnings. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--error.c2
-rw-r--r--io.c27
-rw-r--r--test/ruby/test_io_m17n.rb8
4 files changed, 27 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 260219d..2281372 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Sun Dec 13 18:46:31 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Dec 13 18:49:25 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (parse_mode_enc): preserve encoding of mode string in
+ warnings.
* io.c (io_encname_bom_p): check BOM prefix only, not including
UTF prefix.
diff --git a/error.c b/error.c
index 24f5413..0a7b274 100644
--- a/error.c
+++ b/error.c
@@ -231,7 +231,6 @@ rb_warn(const char *fmt, ...)
rb_write_error_str(mesg);
}
-#if 0
void
rb_enc_warn(rb_encoding *enc, const char *fmt, ...)
{
@@ -245,7 +244,6 @@ rb_enc_warn(rb_encoding *enc, const char *fmt, ...)
va_end(args);
rb_write_error_str(mesg);
}
-#endif
/* rb_warning() reports only in verbose mode */
void
diff --git a/io.c b/io.c
index 9c9e3f1..05d36e3 100644
--- a/io.c
+++ b/io.c
@@ -5054,13 +5054,14 @@ rb_io_ext_int_to_encs(rb_encoding *ext, rb_encoding *intern, rb_encoding **enc,
}
static void
-unsupported_encoding(const char *name)
+unsupported_encoding(const char *name, rb_encoding *enc)
{
- rb_warn("Unsupported encoding %s ignored", name);
+ rb_enc_warn(enc, "Unsupported encoding %s ignored", name);
}
static void
-parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
+parse_mode_enc(const char *estr, rb_encoding *estr_enc,
+ rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
{
const char *p;
char encname[ENCODING_MAXNAMELEN+1];
@@ -5080,7 +5081,7 @@ parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p, int
fmode |= FMODE_SETENC_BY_BOM;
}
else {
- rb_warn("BOM with non-UTF encoding %s is nonsense", estr);
+ rb_enc_warn(estr_enc, "BOM with non-UTF encoding %s is nonsense", estr);
fmode &= ~FMODE_SETENC_BY_BOM;
}
}
@@ -5101,7 +5102,7 @@ parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p, int
ext_enc = rb_enc_from_index(idx);
else {
if (idx != -2)
- unsupported_encoding(estr);
+ unsupported_encoding(estr, estr_enc);
ext_enc = NULL;
}
@@ -5114,7 +5115,7 @@ parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p, int
else {
idx2 = rb_enc_find_index(p);
if (idx2 < 0)
- unsupported_encoding(p);
+ unsupported_encoding(p, estr_enc);
else if (!(fmode & FMODE_SETENC_BY_BOM) && (idx2 == idx)) {
int_enc = (rb_encoding *)Qnil;
}
@@ -5181,7 +5182,8 @@ rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2
if (!NIL_P(encoding)) {
extracted = 1;
if (!NIL_P(tmp = rb_check_string_type(encoding))) {
- parse_mode_enc(StringValueCStr(tmp), enc_p, enc2_p, fmode_p);
+ parse_mode_enc(StringValueCStr(tmp), rb_enc_get(tmp),
+ enc_p, enc2_p, fmode_p);
}
else {
rb_io_ext_int_to_encs(rb_to_encoding(encoding), NULL, enc_p, enc2_p, 0);
@@ -5286,7 +5288,7 @@ rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash,
p = strchr(p, ':');
if (p) {
has_enc = 1;
- parse_mode_enc(p+1, &enc, &enc2, &fmode);
+ parse_mode_enc(p+1, rb_enc_get(vmode), &enc, &enc2, &fmode);
}
else {
rb_encoding *e;
@@ -5592,7 +5594,8 @@ rb_file_open_internal(VALUE io, VALUE filename, const char *modestr)
convconfig_t convconfig;
if (p) {
- parse_mode_enc(p+1, &convconfig.enc, &convconfig.enc2, &fmode);
+ parse_mode_enc(p+1, rb_usascii_encoding(),
+ &convconfig.enc, &convconfig.enc2, &fmode);
}
else {
rb_encoding *e;
@@ -9429,7 +9432,7 @@ static rb_encoding *
find_encoding(VALUE v)
{
rb_encoding *enc = rb_find_encoding(v);
- if (!enc) unsupported_encoding(StringValueCStr(v));
+ if (!enc) rb_warn("Unsupported encoding %"PRIsVALUE" ignored", v);
return enc;
}
@@ -9475,8 +9478,8 @@ io_encoding_set(rb_io_t *fptr, VALUE v1, VALUE v2, VALUE opt)
}
else {
tmp = rb_check_string_type(v1);
- if (!NIL_P(tmp) && rb_enc_asciicompat(rb_enc_get(tmp))) {
- parse_mode_enc(RSTRING_PTR(tmp), &enc, &enc2, NULL);
+ if (!NIL_P(tmp) && rb_enc_asciicompat(enc = rb_enc_get(tmp))) {
+ parse_mode_enc(RSTRING_PTR(tmp), enc, &enc, &enc2, NULL);
SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags);
ecflags = rb_econv_prepare_options(opt, &ecopts, ecflags);
}
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index fb99c0c..a91fcce 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -2107,6 +2107,14 @@ EOT
open(IO::NULL, "w:bom|us-ascii") {|f| enc = f.external_encoding}
}
assert_equal(Encoding::US_ASCII, enc)
+
+ tlhInganHol = "\u{f8e4 f8d9 f8d7 f8dc f8d0 f8db} \u{f8d6 f8dd f8d9}"
+ EnvUtil.with_default_external(Encoding::UTF_8) {
+ assert_warn(/#{tlhInganHol}/) {
+ open(IO::NULL, "w:bom|#{tlhInganHol}") {|f| enc = f.external_encoding}
+ }
+ }
+ assert_nil(enc)
end
def test_cbuf