From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22771 invoked by alias); 10 Mar 2013 20:17:57 -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: 31141 Received: (qmail 23452 invoked from network); 10 Mar 2013 20:17:55 -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.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 209.85.212.176 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-proxyuser-ip:date:from:to:subject:message-id :in-reply-to:references:x-mailer:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=UpASFfByB6DkNq8kfTg5Jh6sPkPGgDfmHLpIYealpW8=; b=ZxfTrt8Psm2tUw4vbOxR5+Llx4wkNwUc2kAZVkW4yhWMNJe+GVynp2zmzq2nk/sL4F 6Ymkc5VPucCyx8spsCdiG7htV+goKYxS0v2nrqHzeaTpXeZBo17wAQML1iOpdGFUmy1g GmATJZa3tJy47KLsq7x1QKACdy9B+xk8phTllL5cxw/HN/b3XiF6eC5CwP0HAv3RyQTy g2pGk0ArkgDnItlJne0s93cVoC1/AEL9JBvrYz2Kx57fj6AKv90tV2RYQfpFvZnKJNCd A53246FMfYJObFW1ITCSgdEzwvOxDxyS97OrYhB77jusqqfK5CpGze5lfWs5kO3o62RG 2FJg== X-Received: by 10.180.75.177 with SMTP id d17mr8731647wiw.16.1362946666405; Sun, 10 Mar 2013 13:17:46 -0700 (PDT) X-ProxyUser-IP: 86.26.6.143 Date: Sun, 10 Mar 2013 20:17:41 +0000 From: Peter Stephenson To: zsh workers Subject: Re: Somewhat unexpected results of {myfd}>&1 when noclobber set Message-ID: <20130310201741.0658434b@pws-pc.ntlworld.com> In-Reply-To: <20130310185204.47d755e8@pws-pc.ntlworld.com> References: <130309071252.ZM19892@torch.brasslantern.com> <20130310185204.47d755e8@pws-pc.ntlworld.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQnnM+hboNIwjemi26ZhbHIE6jU5g0vxD19Dh/mlbdDsn+6OFYV2rQNjDUEIKJlk5wL4sjJf On Sun, 10 Mar 2013 18:52:04 +0000 Peter Stephenson wrote: > On Sat, 09 Mar 2013 07:12:52 -0800 > Bart Schaefer wrote: > > On Mar 9, 11:33am, Mikael Magnusson wrote: > > } > > } % bar=( 14 15 ) > > } % : {bar}>&1 > > } zsh: bad math expression: operator expected at `15' > > } % echo $bar > > } 16 > > > > This is clearly a bug. Failing the math eval should either abort the > > entire operation, or not print the warning. I think the latter would > > be considered the intended behavior, that is, bar does not contain a > > descriptor so it simply gets assigned a new one by the redirection. > > I suppose so >... > But I think Michael's right that to get that effect we don't want the > matheval at all --- we just want to see if foo contains an integer (it > looks like we also check if it's a previously opened fd after retrieving it). Here's my go. Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.215 diff -p -u -r1.215 exec.c --- Src/exec.c 13 Dec 2012 10:37:00 -0000 1.215 +++ Src/exec.c 10 Mar 2013 20:16:44 -0000 @@ -1885,7 +1885,14 @@ checkclobberparam(struct redir *f) return 0; } - if (!isset(CLOBBER) && (fd = (int)getintvalue(v)) && + /* + * We can't clobber the value in the parameter if it's + * already an opened file descriptor --- that means it's a decimal + * integer corresponding to an opened file descriptor, + * not merely an expression that evaluates to a file descriptor. + */ + if (!isset(CLOBBER) && (s = getstrvalue(v)) && + (fd = (int)zstrtol(s, &s, 10)) >= 0 && !*s && fd <= max_zsh_fd && fdtable[fd] == FDT_EXTERNAL) { zwarn("can't clobber parameter %s containing file descriptor %d", f->varid, fd); Index: Test/A04redirect.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/A04redirect.ztst,v retrieving revision 1.25 diff -p -u -r1.25 A04redirect.ztst --- Test/A04redirect.ztst 15 Nov 2012 21:08:16 -0000 1.25 +++ Test/A04redirect.ztst 10 Mar 2013 20:16:44 -0000 @@ -328,6 +328,17 @@ 1q:NO_CLOBBER prevents overwriting parameter with allocated fd ?(eval):4: can't clobber parameter myfd containing file descriptor $myfd + (setopt noclobber + exec {myfd}>logfile2b + print First open >&$myfd + rm -f logfile2b # prevent normal file no_clobberation + myotherfd="${myfd}+0" + exec {myotherfd}>logfile2b + print Overwritten >&$myotherfd) + cat logfile2b +0:NO_CLOBBER doesn't complain about any other expression +>Overwritten + (exec {myfd}>logfile4 echo $myfd exec {myfd}>&- -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/