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

ruby-changes:34924

From: nobu <ko1@a...>
Date: Wed, 30 Jul 2014 23:27:24 +0900 (JST)
Subject: [ruby-changes:34924] nobu:r47007 (trunk): signal.c: preserve encoding

nobu	2014-07-30 23:27:15 +0900 (Wed, 30 Jul 2014)

  New Revision: 47007

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

  Log:
    signal.c: preserve encoding
    
    * signal.c (rb_f_kill, trap_signm): preserve argument encoding in
      error messages.

  Modified files:
    trunk/signal.c
    trunk/test/ruby/test_signal.rb
Index: test/ruby/test_signal.rb
===================================================================
--- test/ruby/test_signal.rb	(revision 47006)
+++ test/ruby/test_signal.rb	(revision 47007)
@@ -73,6 +73,7 @@ class TestSignal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L73
 
   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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L163
 
       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
Index: signal.c
===================================================================
--- signal.c	(revision 47006)
+++ signal.c	(revision 47007)
@@ -397,7 +397,7 @@ rb_f_kill(int argc, const VALUE *argv) https://github.com/ruby/ruby/blob/trunk/signal.c#L397
     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) https://github.com/ruby/ruby/blob/trunk/signal.c#L410
 
       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) https://github.com/ruby/ruby/blob/trunk/signal.c#L435
       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) https://github.com/ruby/ruby/blob/trunk/signal.c#L1049
       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) https://github.com/ruby/ruby/blob/trunk/signal.c#L1058
 	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;
 }

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

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