zsh-workers
 help / color / mirror / code / Atom feed
* Re: autoload bug in 2.6-beta10
       [not found] <199509081910.AA14139@intruder.wiltel.com>
  1995-09-08 20:04 ` autoload bug in 2.6-beta10 Zefram
@ 1995-09-11 13:41 ` P.Stephenson
  1 sibling, 0 replies; 2+ messages in thread
From: P.Stephenson @ 1995-09-11 13:41 UTC (permalink / raw)
  To: Zsh hackers list

alex_ramos@wiltel.com wrote:
> 
> It appears that parameters are not passed to autoload functions
> in 2.6-beta10. Sorry if this had already been reported, but I
> joined the mailing list fairly recently.
> 
> e.g. 
> 	foo() { echo $1 }
> 
> If this function is autoloaded, then invoking "foo test" results
> in echoing a blank line.

Yes, I missed this when I wrote the ksh-compatible autoload code.  The
second problem---as noted by Zefram---is that that code seems to have
disappeared anyway (contrary to what the manual page still says).
Here's a new version of it actually for Richard's 2.6-test2
non-release.  It's a bit more reliable since I've explicitly tested
whether the defined function exists and has changed, which I did a
more roundabout way before.  I fixed the argument problem by having
doshfunc() not destroy the list, which requires a couple of extra
lines of code.

*** Src/exec.c.autoload	Fri Sep  8 17:18:07 1995
--- Src/exec.c	Mon Sep 11 14:31:43 1995
***************
*** 2286,2291 ****
--- 2286,2292 ----
  {
      List funcdef;
      char *nam;
+     int done = 0;
  
      if (errflag)
  	return;
***************
*** 2302,2315 ****
  	}
  	permalloc();
  	shf->flags &= ~PM_UNDEFINED;
! 	shf->funcdef = (List) dupstruct(funcdef);
  	heapalloc();
  	popheap();
      } else if (!shf->funcdef) {
  	return;
      }
  
!     doshfunc(shf->funcdef, cmd->args, shf->flags, 0);
  }
  
  /* execute a shell function */
--- 2303,2327 ----
  	}
  	permalloc();
  	shf->flags &= ~PM_UNDEFINED;
! 	funcdef = shf->funcdef = (List) dupstruct(funcdef);
  	heapalloc();
  	popheap();
+ 
+ 	doshfunc(shf->funcdef, cmd->args, shf->flags, 0);
+ 	/* See if this file defined the autoloaded function by name */
+ 	shf = (Shfunc) shfunctab->getnode(shfunctab, nam);
+ 	if (!shf || !shf->funcdef || shf->funcdef == funcdef) {
+ 	    /* It didn't:  that means we have already executed the
+ 	     * function itself.
+ 	     */
+ 	    done++;
+ 	}
      } else if (!shf->funcdef) {
  	return;
      }
  
!     if (!done)
! 	doshfunc(shf->funcdef, cmd->args, shf->flags, 0);
  }
  
  /* execute a shell function */
***************
*** 2347,2357 ****
  	opts[XTRACE] = OPT_SET;
      opts[PRINTEXITVALUE] = OPT_UNSET;
      if (doshargs) {
  	pparams = x =
  	    (char **) zcalloc(((sizeof *x) * (1 + countlinknodes(doshargs))));
! 	argzero = ztrdup(ugetnode(doshargs));
! 	while ((*x = (char *) ugetnode(doshargs)))
! 	    *x = ztrdup(*x), x++;
      } else {
  	pparams = (char **) zcalloc(sizeof *pparams);
  	argzero = ztrdup(argzero);
--- 2359,2371 ----
  	opts[XTRACE] = OPT_SET;
      opts[PRINTEXITVALUE] = OPT_UNSET;
      if (doshargs) {
+ 	LinkNode node = doshargs->first;
  	pparams = x =
  	    (char **) zcalloc(((sizeof *x) * (1 + countlinknodes(doshargs))));
! 	argzero = ztrdup((char *)node->dat);
! 	node = node->next;
! 	for (; node; node = node->next, x++)
! 	    *x = ztrdup((char *)node->dat);
      } else {
  	pparams = (char **) zcalloc(sizeof *pparams);
  	argzero = ztrdup(argzero);

-- 
Peter Stephenson <P.Stephenson@swansea.ac.uk>  Tel: +44 1792 205678 extn. 4461
WWW:  http://python.swan.ac.uk/~pypeters/      Fax: +44 1792 295324
Department of Physics, University of Wales, Swansea,
Singleton Park, Swansea, SA2 8PP, U.K.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: autoload bug in 2.6-beta10
       [not found] <199509081910.AA14139@intruder.wiltel.com>
@ 1995-09-08 20:04 ` Zefram
  1995-09-11 13:41 ` P.Stephenson
  1 sibling, 0 replies; 2+ messages in thread
From: Zefram @ 1995-09-08 20:04 UTC (permalink / raw)
  To: alex_ramos; +Cc: Z Shell workers mailing list

>It appears that parameters are not passed to autoload functions
>in 2.6-beta10. Sorry if this had already been reported, but I
>joined the mailing list fairly recently.
>
>e.g. 
>	foo() { echo $1 }
>
>If this function is autoloaded, then invoking "foo test" results
>in echoing a blank line.

This is not a bug.  At least, not entirely.  Autoloaded function files
should not contain the foo() bit, as the entire contents of the file is
taken as the contents of the function.  The first time you run the
undefined function, it just redefines itself.  The second time, it will
do what you want.  This is explained in section C5 of the Zsh FAQ.

But zsh is supposed to accept the Korn shell syntax, as of a few betas
ago, so there is a bug here.

-zefram


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1995-09-11 13:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <199509081910.AA14139@intruder.wiltel.com>
1995-09-08 20:04 ` autoload bug in 2.6-beta10 Zefram
1995-09-11 13:41 ` P.Stephenson

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).