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

ruby-changes:17434

From: naruse <ko1@a...>
Date: Mon, 11 Oct 2010 17:43:37 +0900 (JST)
Subject: [ruby-changes:17434] Ruby:r29439 (trunk): * error.c (syserr_initialize): use mesg's encoding when locale

naruse	2010-10-11 17:43:31 +0900 (Mon, 11 Oct 2010)

  New Revision: 29439

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

  Log:
    * 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]

  Modified files:
    trunk/ChangeLog
    trunk/error.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29438)
+++ ChangeLog	(revision 29439)
@@ -1,3 +1,9 @@
+Mon Oct 11 17:42:54 2010  NARUSE, Yui  <naruse@r...>
+
+	* 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@r...>
 
 	* error.c (syserr_initialize): set the encoding of Errno::*#message
Index: error.c
===================================================================
--- error.c	(revision 29438)
+++ error.c	(revision 29439)
@@ -1048,16 +1048,23 @@
     if (!NIL_P(error)) err = strerror(NUM2INT(error));
     else err = "unknown error";
     if (!NIL_P(mesg)) {
+	rb_encoding *le = rb_locale_encoding();
 	VALUE str = mesg;
 
 	StringValue(str);
 	mesg = rb_sprintf("%s - %.*s", err,
 			  (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 {
 	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_iv_set(self, "errno", error);
     return self;

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

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