ruby-changes:6568
From: nobu <ko1@a...>
Date: Wed, 16 Jul 2008 18:04:55 +0900 (JST)
Subject: [ruby-changes:6568] Ruby:r18084 (trunk): * signal.c (signal_exec, trap_handler): trap accepts a string as
nobu 2008-07-16 18:04:37 +0900 (Wed, 16 Jul 2008) New Revision: 18084 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18084 Log: * signal.c (signal_exec, trap_handler): trap accepts a string as command. [ruby-dev:35533] Modified files: trunk/ChangeLog trunk/signal.c Index: ChangeLog =================================================================== --- ChangeLog (revision 18083) +++ ChangeLog (revision 18084) @@ -1,3 +1,8 @@ +Wed Jul 16 18:04:34 2008 Nobuyoshi Nakada <nobu@r...> + + * signal.c (signal_exec, trap_handler): trap accepts a string as + command. [ruby-dev:35533] + Wed Jul 16 00:04:30 2008 Yusuke Endoh <mame@t...> * test/ruby/envutil.rb (Test::Unit::Assertions#assert_in_out_err): new Index: signal.c =================================================================== --- signal.c (revision 18083) +++ signal.c (revision 18084) @@ -391,6 +391,7 @@ static struct { VALUE cmd; + int safe; } trap_list[NSIG]; static rb_atomic_t trap_pending_list[NSIG]; #if 0 @@ -578,6 +579,11 @@ { rb_proc_t *proc; VALUE signum = INT2FIX(sig); + + if (TYPE(cmd) == T_STRING) { + rb_eval_cmd(cmd, rb_ary_new3(1, signum), trap_list[sig].safe); + return; + } GetProcPtr(cmd, proc); vm_invoke_proc(GET_THREAD(), proc, proc->block.self, 1, &signum, 0); } @@ -713,15 +719,10 @@ return func; } -static RETSIGTYPE -wrong_trap(int sig) -{ -} - static sighandler_t trap_handler(VALUE *cmd, int sig) { - sighandler_t func = wrong_trap; + sighandler_t func = sighandler; VALUE command; if (NIL_P(*cmd)) { @@ -731,6 +732,7 @@ command = rb_check_string_type(*cmd); if (!NIL_P(command)) { SafeStringValue(command); /* taint check */ + *cmd = command; switch (RSTRING_LEN(command)) { case 0: goto sig_ign; @@ -763,19 +765,14 @@ break; case 4: if (strncmp(RSTRING_PTR(command), "EXIT", 4) == 0) { - func = sighandler; *cmd = Qundef; } break; } - if (func == wrong_trap) { - rb_raise(rb_eArgError, "wrong trap - %s", RSTRING_PTR(command)); - } } else { rb_proc_t *proc; GetProcPtr(*cmd, proc); - func = sighandler; } } @@ -835,6 +832,7 @@ } trap_list[sig].cmd = command; + trap_list[sig].safe = rb_safe_level(); /* enable at least specified signal. */ #if USE_TRAP_MASK #ifdef HAVE_SIGPROCMASK -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/