mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* signal.c (sig_signame): implements Signal.signame method
[Feature #5613] * test/ruby/test_signal.rb (test_signame): adds test for above * NEWS: add an item about above git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
92cef134b5
commit
58282ed667
4 changed files with 49 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Tue Nov 20 08:36:15 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
|
* signal.c (sig_signame): implements Signal.signame method
|
||||||
|
[Feature #5613]
|
||||||
|
* test/ruby/test_signal.rb (test_signame): adds test for above
|
||||||
|
* NEWS: add an item about above
|
||||||
|
|
||||||
Mon Nov 19 16:30:59 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Mon Nov 19 16:30:59 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* struct.c (rb_struct_each_pair): yield associated pairs so that
|
* struct.c (rb_struct_each_pair): yield associated pairs so that
|
||||||
|
|
3
NEWS
3
NEWS
|
@ -105,6 +105,9 @@ with all sufficient information, see the ChangeLog file.
|
||||||
* added Range#bsearch for binary search.
|
* added Range#bsearch for binary search.
|
||||||
|
|
||||||
* Signal
|
* Signal
|
||||||
|
* added method:
|
||||||
|
* added Signal.signame which returns signal name
|
||||||
|
|
||||||
* incompatible changes:
|
* incompatible changes:
|
||||||
* Signal.trap raises ArgumentError when :SEGV, :BUS, :ILL, :FPE, :VTALRM
|
* Signal.trap raises ArgumentError when :SEGV, :BUS, :ILL, :FPE, :VTALRM
|
||||||
are specified.
|
are specified.
|
||||||
|
|
21
signal.c
21
signal.c
|
@ -207,6 +207,26 @@ signo2signm(int no)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* Signal.signame(signo) -> string
|
||||||
|
*
|
||||||
|
* convert signal number to signal name
|
||||||
|
*
|
||||||
|
* Signal.trap("INT") { |signo| puts Signal.signame(signo) }
|
||||||
|
* Process.kill("INT", 0)
|
||||||
|
*
|
||||||
|
* <em>produces:</em>
|
||||||
|
*
|
||||||
|
* INT
|
||||||
|
*/
|
||||||
|
static VALUE
|
||||||
|
sig_signame(VALUE recv, VALUE signo)
|
||||||
|
{
|
||||||
|
const char *signame = signo2signm(NUM2INT(signo));
|
||||||
|
return rb_str_new_cstr(signame);
|
||||||
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
ruby_signal_name(int no)
|
ruby_signal_name(int no)
|
||||||
{
|
{
|
||||||
|
@ -1086,6 +1106,7 @@ Init_signal(void)
|
||||||
rb_define_global_function("trap", sig_trap, -1);
|
rb_define_global_function("trap", sig_trap, -1);
|
||||||
rb_define_module_function(mSignal, "trap", sig_trap, -1);
|
rb_define_module_function(mSignal, "trap", sig_trap, -1);
|
||||||
rb_define_module_function(mSignal, "list", sig_list, 0);
|
rb_define_module_function(mSignal, "list", sig_list, 0);
|
||||||
|
rb_define_module_function(mSignal, "signame", sig_signame, 1);
|
||||||
|
|
||||||
rb_define_method(rb_eSignal, "initialize", esignal_init, -1);
|
rb_define_method(rb_eSignal, "initialize", esignal_init, -1);
|
||||||
rb_define_method(rb_eSignal, "signo", esignal_signo, 0);
|
rb_define_method(rb_eSignal, "signo", esignal_signo, 0);
|
||||||
|
|
|
@ -240,4 +240,22 @@ EOS
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_signame
|
||||||
|
return unless Process.respond_to?(:kill)
|
||||||
|
|
||||||
|
begin
|
||||||
|
10.times do
|
||||||
|
caught = 0
|
||||||
|
signame = "wrong"
|
||||||
|
|
||||||
|
Signal.trap("INT") { |signo| signame = Signal.signame(signo); caught = 1; }
|
||||||
|
Process.kill("INT", 0)
|
||||||
|
|
||||||
|
sleep 0.01 while caught==0
|
||||||
|
assert_equal(signame, "INT")
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
Signal.trap("INT", "DEFAULT")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue