zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: PATCH: PRINT_EXIT_VALUE with anonymous functions, again
Date: Fri, 13 Feb 2015 10:48:49 +0000	[thread overview]
Message-ID: <20150213104849.701782fb@pwslap01u.europe.root.pri> (raw)

Let's stick with an easy, unambiguously effective fix for this.  As
this is local there is no change to the simple / complex nature of the
command.

pws


diff --git a/Src/exec.c b/Src/exec.c
index 302e2b5..a60d4ff 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3359,9 +3359,9 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		zcontext_restore();
 	    } else
 		redir_prog = NULL;
-	    
+
 	    lastval = execfuncdef(state, redir_prog);
-	} 
+	}
 	else if (type >= WC_CURSH) {
 	    if (last1 == 1)
 		do_exec = 1;
@@ -4488,6 +4488,16 @@ execfuncdef(Estate state, Eprog redir_prog)
 	    execshfunc(shf, args);
 	    ret = lastval;
 
+	    if (isset(PRINTEXITVALUE) && isset(SHINSTDIN) &&
+		lastval) {
+#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD)
+		fprintf(stderr, "zsh: exit %lld\n", lastval);
+#else
+		fprintf(stderr, "zsh: exit %ld\n", (long)lastval);
+#endif
+		fflush(stderr);
+	    }
+
 	    freeeprog(shf->funcdef);
 	    if (shf->redir) /* shouldn't be */
 		freeeprog(shf->redir);
diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index c6af803..3213534 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -795,12 +795,12 @@
 1:PRINT_EXIT_VALUE option
 ?zsh: exit 1
 
-#  $ZTST_testdir/../Src/zsh -f <<<'
-#      setopt printexitvalue
-#      () { false; }
-#  '
-#1:PRINT_EXIT_VALUE option for anonymous function
-#?zsh: exit 1
+  $ZTST_testdir/../Src/zsh -f <<<'
+      setopt printexitvalue
+      () { false; }
+  '
+1:PRINT_EXIT_VALUE option for anonymous function
+?zsh: exit 1
 
   setopt promptbang
   print -P !


-- 
Peter Stephenson | Principal Engineer Samsung Cambridge Solution Centre
Email: p.stephenson@samsung.com | Phone: +44 1223 434724 |
www.samsung.com


             reply	other threads:[~2015-02-13 10:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-13 10:48 Peter Stephenson [this message]
2015-02-13 21:27 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150213104849.701782fb@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).