ruby-changes:37720
From: nobu <ko1@a...>
Date: Mon, 2 Mar 2015 13:04:48 +0900 (JST)
Subject: [ruby-changes:37720] nobu:r49801 (trunk): signal.c: nil for invalid signum
nobu 2015-03-02 13:04:30 +0900 (Mon, 02 Mar 2015) New Revision: 49801 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49801 Log: signal.c: nil for invalid signum * signal.c (sig_signame): return nil if the argument is a valid signal number. Modified files: trunk/ChangeLog trunk/signal.c trunk/test/ruby/test_signal.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 49800) +++ ChangeLog (revision 49801) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Mar 2 13:04:27 2015 Nobuyoshi Nakada <nobu@r...> + + * signal.c (sig_signame): return nil if the argument is a valid + signal number. + Mon Mar 2 12:05:04 2015 Naohisa Goto <ngotogenome@g...> * test/net/ftp/test_ftp.rb (create_ftp_server): set SO_OOBINLINE Index: test/ruby/test_signal.rb =================================================================== --- test/ruby/test_signal.rb (revision 49800) +++ test/ruby/test_signal.rb (revision 49801) @@ -218,6 +218,15 @@ class TestSignal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L218 end def test_signame + Signal.list.each do |name, num| + assert_equal(num, Signal.list[Signal.signame(num)], name) + end + assert_nil(Signal.signame(-1)) + signums = Signal.list.invert + assert_nil(Signal.signame((1..1000).find {|num| !signums[num]})) + end + + def test_signame_delivered 10.times do IO.popen([EnvUtil.rubybin, "-e", <<EOS, :err => File::NULL]) do |child| Signal.trap("INT") do |signo| Index: signal.c =================================================================== --- signal.c (revision 49800) +++ signal.c (revision 49801) @@ -257,6 +257,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/signal.c#L257 sig_signame(VALUE recv, VALUE signo) { const char *signame = signo2signm(NUM2INT(signo)); + if (!signame) return Qnil; return rb_str_new_cstr(signame); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/