зеркало из https://github.com/github/ruby.git
signal.c: preserve encoding
* signal.c (esignal_init): preserve encoding in error messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45483 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
03f0ca4c81
Коммит
d14458fb41
15
signal.c
15
signal.c
|
@ -208,6 +208,8 @@ static const struct signals {
|
||||||
{NULL, 0}
|
{NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char signame_prefix[3] = "SIG";
|
||||||
|
|
||||||
static int
|
static int
|
||||||
signm2signo(const char *nm)
|
signm2signo(const char *nm)
|
||||||
{
|
{
|
||||||
|
@ -298,11 +300,16 @@ esignal_init(int argc, VALUE *argv, VALUE self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
int len = sizeof(signame_prefix);
|
||||||
signm = SYMBOL_P(sig) ? rb_id2name(SYM2ID(sig)) : StringValuePtr(sig);
|
signm = SYMBOL_P(sig) ? rb_id2name(SYM2ID(sig)) : StringValuePtr(sig);
|
||||||
if (strncmp(signm, "SIG", 3) == 0) signm += 3;
|
if (strncmp(signm, signame_prefix, len) == 0) {
|
||||||
|
signm += len;
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
signo = signm2signo(signm);
|
signo = signm2signo(signm);
|
||||||
if (!signo) {
|
if (!signo) {
|
||||||
rb_raise(rb_eArgError, "unsupported name `SIG%s'", signm);
|
rb_raise(rb_eArgError, "unsupported name `%.*s%"PRIsVALUE"'",
|
||||||
|
len, signame_prefix, sig);
|
||||||
}
|
}
|
||||||
sig = rb_sprintf("SIG%s", signm);
|
sig = rb_sprintf("SIG%s", signm);
|
||||||
}
|
}
|
||||||
|
@ -409,7 +416,7 @@ rb_f_kill(int argc, VALUE *argv)
|
||||||
negative++;
|
negative++;
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
if (strncmp("SIG", s, 3) == 0)
|
if (strncmp(signame_prefix, s, sizeof(signame_prefix)) == 0)
|
||||||
s += 3;
|
s += 3;
|
||||||
if ((sig = signm2signo(s)) == 0)
|
if ((sig = signm2signo(s)) == 0)
|
||||||
rb_raise(rb_eArgError, "unsupported name `SIG%s'", s);
|
rb_raise(rb_eArgError, "unsupported name `SIG%s'", s);
|
||||||
|
@ -919,7 +926,7 @@ trap_signm(VALUE vsig)
|
||||||
s = StringValuePtr(vsig);
|
s = StringValuePtr(vsig);
|
||||||
|
|
||||||
str_signal:
|
str_signal:
|
||||||
if (strncmp("SIG", s, 3) == 0)
|
if (strncmp(signame_prefix, s, sizeof(signame_prefix)) == 0)
|
||||||
s += 3;
|
s += 3;
|
||||||
sig = signm2signo(s);
|
sig = signm2signo(s);
|
||||||
if (sig == 0 && strcmp(s, "EXIT") != 0)
|
if (sig == 0 && strcmp(s, "EXIT") != 0)
|
||||||
|
|
|
@ -79,6 +79,7 @@ class TestSignal < Test::Unit::TestCase
|
||||||
assert_raise(ArgumentError) { SignalException.new }
|
assert_raise(ArgumentError) { SignalException.new }
|
||||||
assert_raise(ArgumentError) { SignalException.new(-1) }
|
assert_raise(ArgumentError) { SignalException.new(-1) }
|
||||||
assert_raise(ArgumentError) { SignalException.new(:XXXXXXXXXX) }
|
assert_raise(ArgumentError) { SignalException.new(:XXXXXXXXXX) }
|
||||||
|
assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) { SignalException.new("\u{30eb 30d3 30fc}") }
|
||||||
Signal.list.each do |signm, signo|
|
Signal.list.each do |signm, signo|
|
||||||
next if signm == "EXIT"
|
next if signm == "EXIT"
|
||||||
assert_equal(SignalException.new(signm).signo, signo)
|
assert_equal(SignalException.new(signm).signo, signo)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче