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

ruby-changes:36562

From: nobu <ko1@a...>
Date: Sat, 29 Nov 2014 09:37:17 +0900 (JST)
Subject: [ruby-changes:36562] nobu:r48643 (trunk): error.c: simplify message building

nobu	2014-11-29 09:37:12 +0900 (Sat, 29 Nov 2014)

  New Revision: 48643

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

  Log:
    error.c: simplify message building
    
    * error.c (syserr_initialize): simplify message building and get
      rid of potential invalid byte sequence.

  Modified files:
    trunk/ChangeLog
    trunk/error.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48642)
+++ ChangeLog	(revision 48643)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Nov 29 09:37:10 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* error.c (syserr_initialize): simplify message building and get
+	  rid of potential invalid byte sequence.
+
 Sat Nov 29 06:09:44 2014  NAKAMURA Usaku  <usa@r...>
 
 	* eval_error.c (error_print): respect the encoding of the message.
Index: error.c
===================================================================
--- error.c	(revision 48642)
+++ error.c	(revision 48643)
@@ -1341,7 +1341,7 @@ syserr_initialize(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/error.c#L1341
     char *strerror();
 #endif
     const char *err;
-    VALUE mesg, error, func;
+    VALUE mesg, error, func, errmsg;
     VALUE klass = rb_obj_class(self);
 
     if (klass == rb_eSystemCallError) {
@@ -1365,25 +1365,17 @@ syserr_initialize(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/error.c#L1365
     }
     if (!NIL_P(error)) err = strerror(NUM2INT(error));
     else err = "unknown error";
+
+    errmsg = rb_enc_str_new_cstr(err, rb_locale_encoding());
     if (!NIL_P(mesg)) {
-	rb_encoding *le = rb_locale_encoding();
 	VALUE str = StringValue(mesg);
-	rb_encoding *me = rb_enc_get(mesg);
 
-	if (NIL_P(func))
-	    mesg = rb_sprintf("%s - %"PRIsVALUE, err, mesg);
-	else
-	    mesg = rb_sprintf("%s @ %"PRIsVALUE" - %"PRIsVALUE, err, func, mesg);
-	if (le != me && rb_enc_asciicompat(me)) {
-	    le = me;
-	}/* else assume err is non ASCII string. */
-	OBJ_INFECT(mesg, str);
-	rb_enc_associate(mesg, le);
-    }
-    else {
-	mesg = rb_str_new2(err);
-	rb_enc_associate(mesg, rb_locale_encoding());
+	if (!NIL_P(func)) rb_str_catf(errmsg, " @ %"PRIsVALUE, func);
+	rb_str_catf(errmsg, " - %"PRIsVALUE, str);
+	OBJ_INFECT(errmsg, mesg);
     }
+    mesg = errmsg;
+
     rb_call_super(1, &mesg);
     rb_iv_set(self, "errno", error);
     return self;

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

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