From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9317 invoked by alias); 12 Mar 2014 17:47:36 -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: 32477 Received: (qmail 16962 invoked from network); 12 Mar 2014 17:47:21 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=b0Eoin9ahxTDgT5PhedYAPEpntvErkdtFvx+zEkrWwU=; b=1E6UWj7BpH+e5RQmzChDwPs5GcRHsSzaqCK5mRzwdf4Sjpa1a/LE9ZBxU02bgmYghR MNfa9m+eh3c4MSIC2ro6/dyS2iAp6HScu20Rw4Hh+KJD5ych1drDPOHLrv5OyDbDmNuS 5ouVJz6sMt7EMPALDYOdPbBnrdlNgwXAjr8BHONNB5qgksnRSenCnhyt+Pj88GYIJzci v0IyTCB/zfOJ5QOOjtF+BwKyN26OM1x8Cgvqg8bYbLulrLumZlbFkx9mAQ5w5WxMqTH0 ExMkI+sYCZAY4S9z36oLJvOO8ibaDoGsnRSxo812KVcoj/UeK0lE3rf8Ra8ogHxZlrYd udRA== X-Received: by 10.68.136.2 with SMTP id pw2mr6490078pbb.167.1394646437460; Wed, 12 Mar 2014 10:47:17 -0700 (PDT) Date: Wed, 12 Mar 2014 10:47:14 -0700 From: Eduardo =?utf-8?Q?A=2E_Bustamante_L=C3=B3pez?= To: Peter Stephenson Cc: zsh-workers@zsh.org Subject: Re: Zsh does not follow POSIX when return is called during the action of a trap Message-ID: <20140312174714.GA13516@dualbus.me> References: <20140312153627.GA15209@dualbus.me> <140312095210.ZM13090@torch.brasslantern.com> <20140312170309.48ea7444@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20140312170309.48ea7444@pwslap01u.europe.root.pri> User-Agent: Mutt/1.5.21 (2010-09-15) On Wed, Mar 12, 2014 at 05:03:09PM +0000, Peter Stephenson wrote: > On Wed, 12 Mar 2014 09:52:10 -0700 > Bart Schaefer wrote: > > Have you tried this with the POSIX_TRAPS option set? > > > > Zsh does not in general conform to POSIX at all unless you run it with > > the appropriate compatibility settings. I see. Well, I now ran the code with 'emulate sh' (thanks Peter, for the suggestion). These are the results: | 12 zsh: 2 | 988 zsh: 3 | zsh 5.0.5-dev-0 (x86_64-unknown-linux-gnu) For this new code: | code=' | emulate sh | | trap "(exit 2); return" USR1 | f() { | { echo; kill -USR1 $$; } | exit 3 | return 5 | } | | (exit 7); f | ' | | shells=( | zsh | ) | | for attempt in {1..1000}; do | for shell in "${shells[@]}"; do | printf '%s: %s\n' "$shell" "$($shell -c "$code"; echo $?)" | done | done | sort | uniq -c | | zsh --version > However, I'm trying to work out what happens with the case > > | trap '(exit BEFORE-RETURN); return EXPLICIT-RETURN-VALUE' SIGNAL > | > | fn() { > | (exit BEFORE-ACTION); -block here waiting for signal- > | } > > Should this exit with EXPLICIT-RETURN_VALUE or BEFORE-ACTION? The > latter is easier to implement but my guess (without ploughing through > the standard) is EXPLICIT-RETURN-VALUE is right here. > > pws > Ah, I see. I tested with this: | code=' | emulate sh | | trap "(exit 2); return 9" USR1 | f() { | { echo; kill -USR1 $$; } | exit 3 | return 5 | } | | (exit 7); f | ' | | shells=( | zsh | ) | | for attempt in {1..1000}; do | for shell in "${shells[@]}"; do | printf '%s: %s\n' "$shell" "$($shell -c "$code"; echo $?)" | done | done | sort | uniq -c | | zsh --version And got: | 991 zsh: 3 | 9 zsh: 9 | zsh 5.0.5-dev-0 (x86_64-unknown-linux-gnu) Which is kind of wrong, since it should always be 9, but according to the results, it's mostly 3. POSIX states: | The value of the special parameter '?' shall be set to n, an unsigned | decimal integer, or to the exit status of the last command executed if n is | not specified. If the value of n is greater than 255, the results are | undefined. When return is executed in a trap action, the last command is | considered to be the command that executed immediately preceding the trap | action. So, the result should be 9 ("'?' shall be set to n [...] or the exit status of the last command [...]"). Because in this case 'n' is set. -- Eduardo Alan Bustamante López