Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: autoload bug in 2.6-beta10



alex_ramos@xxxxxxxxxx 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@xxxxxxxxxxxxx>  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.



Messages sorted by: Reverse Date, Date, Thread, Author