From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15285 invoked by alias); 24 Jan 2016 17:17:14 -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: 37765 Received: (qmail 10833 invoked from network); 24 Jan 2016 17:17:11 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Originating-IP: [82.20.18.64] X-Spam: 0 X-Authority: v=2.1 cv=KZcvylsD c=1 sm=1 tr=0 a=tQ56d2wE10i0ATcm3CvKvA==:117 a=tQ56d2wE10i0ATcm3CvKvA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=NLZqzBF-AAAA:8 a=kj9zAlcOel0A:10 a=2Ch1vRBQr9wbNUsOsD8A:9 a=CjuIK1q_8ugA:10 Date: Sun, 24 Jan 2016 17:17:08 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Glitch with "eval" and "autoload" Message-ID: <20160124171708.75438e31@ntlworld.com> In-Reply-To: <20160124152235.5e088b74@ntlworld.com> References: <160123100311.ZM14575@torch.brasslantern.com> <20160124152235.5e088b74@ntlworld.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 24 Jan 2016 15:22:35 +0000 Peter Stephenson wrote: > You shouldn't need to check the name, rather look for (fstpr->tp == > FS_FUNC). That ought to be fairly robust. This is a little bit paranoid; the dupstring probably isn't needed because we already take evasive action for cases like this, and I don't know of a case where funcname will be NULL. pws diff --git a/Src/builtin.c b/Src/builtin.c index 98ecb09..63f964d 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3142,15 +3142,33 @@ bin_functions(char *name, char **argv, Options ops, int func) queue_signals(); if (OPT_MINUS(ops,'X')) { - if ((shf = (Shfunc) shfunctab->getnode(shfunctab, scriptname))) { - DPUTS(!shf->funcdef, - "BUG: Calling autoload from empty function"); + Funcstack fs; + char *funcname = NULL; + for (fs = funcstack; fs; fs = fs->prev) { + if (fs->tp == FS_FUNC) { + /* + * dupstring here is paranoia but unlikely to be + * problematic + */ + funcname = dupstring(fs->name); + break; + } + } + if (!funcname) + { + zerrnam(name, "bad autoload"); + ret = 1; } else { - shf = (Shfunc) zshcalloc(sizeof *shf); - shfunctab->addnode(shfunctab, ztrdup(scriptname), shf); + if ((shf = (Shfunc) shfunctab->getnode(shfunctab, funcname))) { + DPUTS(!shf->funcdef, + "BUG: Calling autoload from empty function"); + } else { + shf = (Shfunc) zshcalloc(sizeof *shf); + shfunctab->addnode(shfunctab, ztrdup(funcname), shf); + } + shf->node.flags = on; + ret = eval_autoload(shf, funcname, ops, func); } - shf->node.flags = on; - ret = eval_autoload(shf, scriptname, ops, func); } else { if (OPT_ISSET(ops,'U') && !OPT_ISSET(ops,'u')) on &= ~PM_UNDEFINED; diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst index 0951e2c..496577f 100644 --- a/Test/C04funcdef.ztst +++ b/Test/C04funcdef.ztst @@ -308,6 +308,19 @@ ?(eval):6: command not found: firstfn1 ?(eval):7: command not found: secondfn1 + ( + fpath=(.) + print "print oops was successfully autoloaded" >oops + oops() { eval autoload -X } + oops + which -x2 oops + ) +0:autoload containing eval +>oops was successfully autoloaded +>oops () { +> print oops was successfully autoloaded +>} + %clean rm -f file.in file.out