summaryrefslogtreecommitdiff
path: root/signal.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-30 14:27:15 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-30 14:27:15 (GMT)
commita0dc245f72afba5889a528074d079d310effeb3b (patch)
treef697efeda011f089e06705246b7d785068bf0c2b /signal.c
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
Diffstat (limited to 'signal.c')
-rw-r--r--signal.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/signal.c b/signal.c
index 3017061..e723e66 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;
}