summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-30 14:27:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-30 14:27:15 +0000
commita0dc245f72afba5889a528074d079d310effeb3b (patch)
treef697efeda011f089e06705246b7d785068bf0c2b
parente5a7c2db988db967140da2e11bdf8bb8e85d7769 (diff)
signal.c: preserve encoding
* signal.c (rb_f_kill, trap_signm): preserve argument encoding in error messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--signal.c23
-rw-r--r--test/ruby/test_signal.rb2
2 files changed, 15 insertions, 10 deletions
diff --git a/signal.c b/signal.c
index 30170610463..e723e6680c1 100644
--- a/signal.c
+++ b/signal.c
@@ -397,7 +397,7 @@ rb_f_kill(int argc, const VALUE *argv)
int negative = 0;
int sig;
int i;
- volatile VALUE str;
+ VALUE str;
const char *s;
rb_secure(2);
@@ -410,21 +410,23 @@ rb_f_kill(int argc, const VALUE *argv)
case T_SYMBOL:
str = rb_sym2str(argv[0]);
- s = RSTRING_PTR(str);
- if (!s) rb_raise(rb_eArgError, "bad signal");
goto str_signal;
case T_STRING:
- s = RSTRING_PTR(argv[0]);
+ str = argv[0];
str_signal:
+ s = RSTRING_PTR(str);
if (s[0] == '-') {
negative++;
s++;
}
if (strncmp(signame_prefix, s, sizeof(signame_prefix)) == 0)
s += 3;
- if ((sig = signm2signo(s)) == 0)
- rb_raise(rb_eArgError, "unsupported name `SIG%s'", s);
+ if ((sig = signm2signo(s)) == 0) {
+ long ofs = s - RSTRING_PTR(str);
+ if (ofs) str = rb_str_subseq(str, ofs, RSTRING_LEN(str)-ofs);
+ rb_raise(rb_eArgError, "unsupported name `SIG%"PRIsVALUE"'", str);
+ }
if (negative)
sig = -sig;
@@ -433,7 +435,6 @@ rb_f_kill(int argc, const VALUE *argv)
default:
str = rb_check_string_type(argv[0]);
if (!NIL_P(str)) {
- s = RSTRING_PTR(str);
goto str_signal;
}
rb_raise(rb_eArgError, "bad signal type %s",
@@ -1048,7 +1049,6 @@ trap_signm(VALUE vsig)
case T_SYMBOL:
vsig = rb_sym2str(vsig);
s = RSTRING_PTR(vsig);
- if (!s) rb_raise(rb_eArgError, "bad signal");
goto str_signal;
default:
@@ -1058,8 +1058,11 @@ trap_signm(VALUE vsig)
if (strncmp(signame_prefix, s, sizeof(signame_prefix)) == 0)
s += 3;
sig = signm2signo(s);
- if (sig == 0 && strcmp(s, "EXIT") != 0)
- rb_raise(rb_eArgError, "unsupported signal SIG%s", s);
+ if (sig == 0 && strcmp(s, "EXIT") != 0) {
+ long ofs = s - RSTRING_PTR(vsig);
+ if (ofs) vsig = rb_str_subseq(vsig, ofs, RSTRING_LEN(vsig)-ofs);
+ rb_raise(rb_eArgError, "unsupported signal SIG%"PRIsVALUE"", vsig);
+ }
}
return sig;
}
diff --git a/test/ruby/test_signal.rb b/test/ruby/test_signal.rb
index 70b6c2bb4c6..251a12db173 100644
--- a/test/ruby/test_signal.rb
+++ b/test/ruby/test_signal.rb
@@ -73,6 +73,7 @@ class TestSignal < Test::Unit::TestCase
def test_invalid_signal_name
assert_raise(ArgumentError) { Process.kill(:XXXXXXXXXX, $$) }
+ assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) { Process.kill("\u{30eb 30d3 30fc}", $$) }
end if Process.respond_to?(:kill)
def test_signal_exception
@@ -162,6 +163,7 @@ class TestSignal < Test::Unit::TestCase
assert_raise(ArgumentError) { Signal.trap("XXXXXXXXXX", "SIG_DFL") }
+ assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) { Signal.trap("\u{30eb 30d3 30fc}", "SIG_DFL") }
ensure
Signal.trap(:INT, oldtrap) if oldtrap
end