* error.c (syserr_initialize): use mesg's encoding when locale
encoding is US-ASCII. If locale encoding is not US-ASCII, assume err has non ASCII characters. [ruby-dev:42358] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
44691b901e
commit
c1b24588d3
@ -1,3 +1,9 @@
|
|||||||
|
Mon Oct 11 17:42:54 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* error.c (syserr_initialize): use mesg's encoding when locale
|
||||||
|
encoding is US-ASCII. If locale encoding is not US-ASCII,
|
||||||
|
assume err has non ASCII characters. [ruby-dev:42358]
|
||||||
|
|
||||||
Mon Oct 11 14:03:54 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
Mon Oct 11 14:03:54 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* error.c (syserr_initialize): set the encoding of Errno::*#message
|
* error.c (syserr_initialize): set the encoding of Errno::*#message
|
||||||
|
9
error.c
9
error.c
@ -1048,16 +1048,23 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
|
|||||||
if (!NIL_P(error)) err = strerror(NUM2INT(error));
|
if (!NIL_P(error)) err = strerror(NUM2INT(error));
|
||||||
else err = "unknown error";
|
else err = "unknown error";
|
||||||
if (!NIL_P(mesg)) {
|
if (!NIL_P(mesg)) {
|
||||||
|
rb_encoding *le = rb_locale_encoding();
|
||||||
VALUE str = mesg;
|
VALUE str = mesg;
|
||||||
|
|
||||||
StringValue(str);
|
StringValue(str);
|
||||||
mesg = rb_sprintf("%s - %.*s", err,
|
mesg = rb_sprintf("%s - %.*s", err,
|
||||||
(int)RSTRING_LEN(str), RSTRING_PTR(str));
|
(int)RSTRING_LEN(str), RSTRING_PTR(str));
|
||||||
|
if (le == rb_usascii_encoding()) {
|
||||||
|
rb_encoding *me = rb_enc_get(mesg);
|
||||||
|
if (le != me && rb_enc_asciicompat(me))
|
||||||
|
le = me;
|
||||||
|
}/* else assume err is non ASCII string. */
|
||||||
|
rb_enc_associate(mesg, le);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mesg = rb_str_new2(err);
|
mesg = rb_str_new2(err);
|
||||||
}
|
|
||||||
rb_enc_associate(mesg, rb_locale_encoding());
|
rb_enc_associate(mesg, rb_locale_encoding());
|
||||||
|
}
|
||||||
rb_call_super(1, &mesg);
|
rb_call_super(1, &mesg);
|
||||||
rb_iv_set(self, "errno", error);
|
rb_iv_set(self, "errno", error);
|
||||||
return self;
|
return self;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user