From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18658 invoked by alias); 11 Sep 2010 19:36:44 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28250 Received: (qmail 13047 invoked from network); 11 Sep 2010 19:36:38 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DATE_IN_PAST_12_24 autolearn=no version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at ntlworld.com designates 81.103.221.56 as permitted sender) From: Peter Stephenson To: zsh-workers@zsh.org (Zsh hackers list) Subject: PATCH: POSIX_TRAPS option X-Mailer: MH-E 8.2; nmh 1.3; GNU Emacs 23.2.1 Date: Fri, 10 Sep 2010 20:31:09 +0100 Message-ID: <7900.1284147069@pws-pc> X-Cloudmark-Analysis: v=1.1 cv=4QByPj+6Iq2k/6L54d+eVKTdgQxdscpRskJJReCfdXo= c=1 sm=0 a=4YI7mmuYAqcA:10 a=NLZqzBF-AAAA:8 a=_ZNXLxWahEx7BjY8HNoA:9 a=cSygifuW9opvDXMBNR0A:7 a=ZXsmrsjNAhjw_Uw8_QrA6uEXEAIA:4 a=_dQi-Dcv4p4A:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 It's high time we were able to treat EXIT traps the same way as other shells. Oddly, POSIX doesn't seem to specify when EXIT traps are actually run, but the implication must be it refers to exiting the shell, not returning from shell functions. Index: Doc/Zsh/options.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v retrieving revision 1.94 diff -p -u -r1.94 options.yo --- Doc/Zsh/options.yo 23 Aug 2010 13:40:43 -0000 1.94 +++ Doc/Zsh/options.yo 10 Sep 2010 19:29:48 -0000 @@ -1876,6 +1876,19 @@ If multibyte character support is not co ignored; all octets with the top bit set may be used in identifiers. This is non-standard but is the traditional zsh behaviour. ) +pindex(POSIX_TRAPS) +pindex(NO_POSIX_TRAPS) +pindex(POSIXTRAPS) +pindex(NOPOSIXTRAPS) +cindex(traps, on function exit) +cindex(traps, POSIX compatibility) +item(tt(POSIX_TRAPS) )( +When the is option is set, the usual zsh behaviour of executing +traps for tt(EXIT) on exit from shell functions is suppressed. +In that case, manipulating tt(EXIT) traps always alters the global +trap for exiting the shell; the tt(LOCAL_TRAPS) option is +ignored for the tt(EXIT) trap. +) pindex(SH_FILE_EXPANSION) pindex(NO_SH_FILE_EXPANSION) pindex(SHFILEEXPANSION) Index: Src/options.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/options.c,v retrieving revision 1.54 diff -p -u -r1.54 options.c --- Src/options.c 16 Mar 2010 09:44:55 -0000 1.54 +++ Src/options.c 10 Sep 2010 19:29:48 -0000 @@ -204,6 +204,7 @@ static struct optname optns[] = { {{NULL, "posixcd", OPT_EMULATE|OPT_BOURNE}, POSIXCD}, {{NULL, "posixidentifiers", OPT_EMULATE|OPT_BOURNE}, POSIXIDENTIFIERS}, {{NULL, "posixjobs", OPT_EMULATE|OPT_BOURNE}, POSIXJOBS}, +{{NULL, "posixtraps", OPT_EMULATE|OPT_BOURNE}, POSIXTRAPS}, {{NULL, "printeightbit", 0}, PRINTEIGHTBIT}, {{NULL, "printexitvalue", 0}, PRINTEXITVALUE}, {{NULL, "privileged", OPT_SPECIAL}, PRIVILEGED}, Index: Src/signals.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/signals.c,v retrieving revision 1.59 diff -p -u -r1.59 signals.c --- Src/signals.c 22 Aug 2010 20:08:57 -0000 1.59 +++ Src/signals.c 10 Sep 2010 19:29:49 -0000 @@ -864,7 +864,8 @@ removetrap(int sig) * one, to aid in removing this one. However, if there's * already one at the current locallevel we just overwrite it. */ - if (!dontsavetrap && (isset(LOCALTRAPS) || sig == SIGEXIT) && + if (!dontsavetrap && + (sig == SIGEXIT ? !isset(POSIXTRAPS) : isset(LOCALTRAPS)) && locallevel && (!trapped || locallevel > (sigtrapped[sig] >> ZSIG_SHIFT))) dosavetrap(sig, locallevel); @@ -932,7 +933,7 @@ starttrapscope(void) * so give it the next higher one. dosavetrap() is called * automatically where necessary. */ - if (sigtrapped[SIGEXIT]) { + if (sigtrapped[SIGEXIT] && !isset(POSIXTRAPS)) { locallevel++; unsettrap(SIGEXIT); locallevel--; @@ -960,7 +961,7 @@ endtrapscope(void) */ if (intrap) exittr = 0; - else if ((exittr = sigtrapped[SIGEXIT])) { + else if (!isset(POSIXTRAPS) && (exittr = sigtrapped[SIGEXIT])) { if (exittr & ZSIG_FUNC) { exitfn = removehashnode(shfunctab, "TRAPEXIT"); } else { @@ -1005,7 +1006,8 @@ endtrapscope(void) } if (exittr) { - dotrapargs(SIGEXIT, &exittr, exitfn); + if (!isset(POSIXTRAPS)) + dotrapargs(SIGEXIT, &exittr, exitfn); if (exittr & ZSIG_FUNC) shfunctab->freenode((HashNode)exitfn); else Index: Src/zsh.h =================================================================== RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v retrieving revision 1.166 diff -p -u -r1.166 zsh.h --- Src/zsh.h 27 May 2010 18:57:34 -0000 1.166 +++ Src/zsh.h 10 Sep 2010 19:29:49 -0000 @@ -1987,6 +1987,7 @@ enum { POSIXCD, POSIXIDENTIFIERS, POSIXJOBS, + POSIXTRAPS, PRINTEIGHTBIT, PRINTEXITVALUE, PRIVILEGED, Index: Test/C03traps.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/C03traps.ztst,v retrieving revision 1.19 diff -p -u -r1.19 C03traps.ztst --- Test/C03traps.ztst 10 May 2010 12:31:49 -0000 1.19 +++ Test/C03traps.ztst 10 Sep 2010 19:29:49 -0000 @@ -371,6 +371,23 @@ 0: EXIT trap set in command substitution >command substitution exited + (cd ..; $ZTST_exe -fc 'setopt posixtraps; + TRAPEXIT() { print Exited; } + fn1() { trap; } + setopt localtraps # should be ignored by EXIT + fn2() { TRAPEXIT() { print No, really exited; } } + fn1 + fn2 + fn1') +0:POSIX_TRAPS option +>TRAPEXIT () { +> print Exited +>} +>TRAPEXIT () { +> print No, really exited +>} +>No, really exited + %clean rm -f TRAPEXIT -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/