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

ruby-changes:33404

From: nobu <ko1@a...>
Date: Mon, 31 Mar 2014 11:34:48 +0900 (JST)
Subject: [ruby-changes:33404] nobu:r45483 (trunk): signal.c: preserve encoding

nobu	2014-03-31 11:34:43 +0900 (Mon, 31 Mar 2014)

  New Revision: 45483

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

  Log:
    signal.c: preserve encoding
    
    * signal.c (esignal_init): preserve 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 45482)
+++ test/ruby/test_signal.rb	(revision 45483)
@@ -79,6 +79,7 @@ class TestSignal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L79
     assert_raise(ArgumentError) { SignalException.new }
     assert_raise(ArgumentError) { SignalException.new(-1) }
     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|
       next if signm == "EXIT"
       assert_equal(SignalException.new(signm).signo, signo)
Index: signal.c
===================================================================
--- signal.c	(revision 45482)
+++ signal.c	(revision 45483)
@@ -208,6 +208,8 @@ static const struct signals { https://github.com/ruby/ruby/blob/trunk/signal.c#L208
     {NULL, 0}
 };
 
+static const char signame_prefix[3] = "SIG";
+
 static int
 signm2signo(const char *nm)
 {
@@ -298,11 +300,16 @@ esignal_init(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/signal.c#L300
 	}
     }
     else {
+	int len = sizeof(signame_prefix);
 	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);
 	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);
     }
@@ -409,7 +416,7 @@ rb_f_kill(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/signal.c#L416
 	    negative++;
 	    s++;
 	}
-	if (strncmp("SIG", s, 3) == 0)
+	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);
@@ -919,7 +926,7 @@ trap_signm(VALUE vsig) https://github.com/ruby/ruby/blob/trunk/signal.c#L926
 	s = StringValuePtr(vsig);
 
       str_signal:
-	if (strncmp("SIG", s, 3) == 0)
+	if (strncmp(signame_prefix, s, sizeof(signame_prefix)) == 0)
 	    s += 3;
 	sig = signm2signo(s);
 	if (sig == 0 && strcmp(s, "EXIT") != 0)

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

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