mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
error.c: simplify message building
* error.c (syserr_initialize): simplify message building and get rid of potential invalid byte sequence. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6bb52d8026
commit
374fcff28c
2 changed files with 15 additions and 18 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sat Nov 29 09:37:10 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Sat Nov 29 06:09:44 2014 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* eval_error.c (error_print): respect the encoding of the message.
|
* eval_error.c (error_print): respect the encoding of the message.
|
||||||
|
|
28
error.c
28
error.c
|
@ -1341,7 +1341,7 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
|
||||||
char *strerror();
|
char *strerror();
|
||||||
#endif
|
#endif
|
||||||
const char *err;
|
const char *err;
|
||||||
VALUE mesg, error, func;
|
VALUE mesg, error, func, errmsg;
|
||||||
VALUE klass = rb_obj_class(self);
|
VALUE klass = rb_obj_class(self);
|
||||||
|
|
||||||
if (klass == rb_eSystemCallError) {
|
if (klass == rb_eSystemCallError) {
|
||||||
|
@ -1365,25 +1365,17 @@ 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)) {
|
|
||||||
rb_encoding *le = rb_locale_encoding();
|
|
||||||
VALUE str = StringValue(mesg);
|
|
||||||
rb_encoding *me = rb_enc_get(mesg);
|
|
||||||
|
|
||||||
if (NIL_P(func))
|
errmsg = rb_enc_str_new_cstr(err, rb_locale_encoding());
|
||||||
mesg = rb_sprintf("%s - %"PRIsVALUE, err, mesg);
|
if (!NIL_P(mesg)) {
|
||||||
else
|
VALUE str = StringValue(mesg);
|
||||||
mesg = rb_sprintf("%s @ %"PRIsVALUE" - %"PRIsVALUE, err, func, mesg);
|
|
||||||
if (le != me && rb_enc_asciicompat(me)) {
|
if (!NIL_P(func)) rb_str_catf(errmsg, " @ %"PRIsVALUE, func);
|
||||||
le = me;
|
rb_str_catf(errmsg, " - %"PRIsVALUE, str);
|
||||||
}/* else assume err is non ASCII string. */
|
OBJ_INFECT(errmsg, mesg);
|
||||||
OBJ_INFECT(mesg, str);
|
|
||||||
rb_enc_associate(mesg, le);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mesg = rb_str_new2(err);
|
|
||||||
rb_enc_associate(mesg, rb_locale_encoding());
|
|
||||||
}
|
}
|
||||||
|
mesg = errmsg;
|
||||||
|
|
||||||
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…
Reference in a new issue