zsh-workers
 help / color / mirror / code / Atom feed
* ksh autoloading
@ 1997-03-26 17:46 Zefram
  1997-03-27 18:15 ` Roderick Schertler
  0 siblings, 1 reply; 6+ messages in thread
From: Zefram @ 1997-03-26 17:46 UTC (permalink / raw)
  To: zsh-workers

-----BEGIN PGP SIGNED MESSAGE-----

This patch changes the way ksh autoloading is handled.  Currently it is
a kludge in execshfunc(), that if a function that was just autoloaded
redefines itself on first execution, it is executed again.  This breaks
on functions that really want to redefine themselves, which some do,
and in any case isn't applied to functions autoloaded for other purposes,
such as chpwd or widget functions.

The new scheme is that when a list has been read from the file and parsed,
it is examined to see if it is *in its entirety* a definition of the
function being loaded.  If it is, then the contents of that definition
is used, rather than the complete list.  This has much better defined
semantics than the old method.

 -zefram

      *** Src/exec.c	1997/03/22 07:00:53	1.53
      --- Src/exec.c	1997/03/26 02:57:18
      ***************
      *** 2482,2505 ****
        	if (!(funcdef = getfpfunc(nam))) {
        	    zerr("function not found: %s", nam, 0);
        	    lastval = 1;
      ! 	} else {
      ! 	    PERMALLOC {
      ! 		shf->flags &= ~PM_UNDEFINED;
      ! 		funcdef = shf->funcdef = (List) dupstruct(funcdef);
      ! 	    } LASTALLOC;
      ! 
      ! 	    /* Execute the function definition, we just retrived */
      ! 	    doshfunc(shf->funcdef, cmd->args, shf->flags, 0);
      ! 
      ! 	    /* See if this file defined the autoloaded function *
      ! 	     * by name.  If so, we execute it again.            */
      ! 	    if ((shf = (Shfunc) shfunctab->getnode(shfunctab, nam))
      ! 		&& shf->funcdef && shf->funcdef != funcdef)
      ! 		doshfunc(shf->funcdef, cmd->args, shf->flags, 0);
      ! 	}
      !     } else
      ! 	/* Normal shell function execution */
      ! 	doshfunc(shf->funcdef, cmd->args, shf->flags, 0);
            if (!list_pipe)
        	deletefilelist(last_file_list);
        }
      --- 2482,2497 ----
        	if (!(funcdef = getfpfunc(nam))) {
        	    zerr("function not found: %s", nam, 0);
        	    lastval = 1;
      ! 	    goto end;
      ! 	}
      ! 	shf->flags &= ~PM_UNDEFINED;
      ! 	PERMALLOC {
      ! 	    shf->funcdef = (List) dupstruct(funcdef);
      ! 	} LASTALLOC;
      !     }
      !     doshfunc(shf->funcdef, cmd->args, shf->flags, 0);
      ! 
      !     end:
            if (!list_pipe)
        	deletefilelist(last_file_list);
        }
      ***************
      *** 2658,2664 ****
        			r = parse_string(d);
        		    } LASTALLOC;
        		    zfree(d, len + 1);
      ! 		    return r;
        		} else {
        		    zfree(d, len + 1);
        		    close(fd);
      --- 2650,2656 ----
        			r = parse_string(d);
        		    } LASTALLOC;
        		    zfree(d, len + 1);
      ! 		    return stripkshdef(r, s);
        		} else {
        		    zfree(d, len + 1);
        		    close(fd);
      ***************
      *** 2669,2674 ****
      --- 2661,2697 ----
        	}
            }
            return NULL;
      + }
      + 
      + /* Handle ksh-style autoloading.  Given the list read from an autoload file, *
      +  * and the name of the function being defined, check to see if the file      *
      +  * consists entirely of a single definition for that function.  If so,       *
      +  * use the contents of that definition.  Otherwise, use the entire file.     */
      + 
      + /**/
      + List
      + stripkshdef(List l, char *name)
      + {
      +     Sublist s;
      +     Pline p;
      +     Cmd c;
      +     if(!l)
      + 	return NULL;
      +     if(l->type != Z_SYNC || l->right)
      + 	return l;
      +     s = l->left;
      +     if(s->flags || s->right)
      + 	return l;
      +     p = s->left;
      +     if(p->right)
      + 	return l;
      +     c = p->left;
      +     if(c->type != FUNCDEF || c->flags ||
      + 	nonempty(c->redir) || nonempty(c->vars) ||
      + 	empty(c->args) || lastnode(c->args) != firstnode(c->args) ||
      + 	strcmp(name, peekfirst(c->args)))
      + 	return l;
      +     return c->u.list;
        }
        
        /* check to see if AUTOCD applies here */

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: ascii

iQCVAwUBMziTIXD/+HJTpU/hAQHmbQP7B++6X39X6L344dwuvXKO23W22kvhWW/T
P0Vc60AOgL/09xfzQO68nOlwawQFFLedtznwwMExpPbAn5lARw81JjTDG1jONyJN
sEtoK31eQHcbBYtbOk17MWF5TeFlsPm7aap2/seKXE/djuS9yUZP6tTjCwN/6A0J
FDwUrNL2yek=
=MxJ5
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 6+ messages in thread
* ksh autoloading
@ 1997-04-01  0:08 Zefram
  0 siblings, 0 replies; 6+ messages in thread
From: Zefram @ 1997-04-01  0:08 UTC (permalink / raw)
  To: zsh-workers

-----BEGIN PGP SIGNED MESSAGE-----

This patch makes autoloading work *exactly* like ksh -- at least, it does
in ksh emulation mode.  There is a new option, KSH_AUTOLOAD (the 110th
option if all my recent ones are accepted), which makes the function
definition file just be sourced, regardless of what (if anything) it does.

The autoloading mechanism is also changed.  Rather than sorting out the
autoloading when looking up the function definition, the autoloading
*is* the definition -- a special type of command, used only in undefined
functions.  When this command gets executed, it autoloads and then calls
the function.  What this buys, other than simplicity and maintainability,
is that in the KSH_AUTOLOAD case it sources the file in the context of the
function execution, as ksh does.  In fact, the file can even declare local
parameters, that are still in scope during the first function execution,
but go out of scope thereafter.

There is one remaining incompatibility between ksh and zsh autoloading.
In ksh, if a command can't be found in $PATH, it is treated as
an autoloaded function and searched for in $FPATH as a fallback.
I'll implement this in a separate patch.

This patch depends on my previous autoloading patch, of course.

 -zefram

begin 644 autoload_patch.gz
M'XL("!MJ/S,"`V%U=&]L;V%D7W!A=&-H`.5;>U?;2);_V_D4178F;1L9+#_!
M3#+'`9-P%@P'S#PZF\/*LFRKL26/'A#2S7[VO8^J4LG()#-)MO?LYJ33=JGJ
MUJW[_-U;<K5:%4>AN_MS/-\=I_XB\8-XYR$LV?O[W=UZ<[=9%_5ZK[7?JS=+
M]H[=>5&KU9Y?8(MZMU??[S5:+ZKY/_A==/:LO8Z@KT),_6#B?2H[:1(N0F=2
M@2&7AZ9IX"9^&,264$_]8&9,,$:%GEQYL27\Q%N6DR0C*CZ(.R<J!\[2JXB=
MG1WQL5*&><=A)#S'G8MP*I*YE\V)1?E^[L,#)_($CL0X)=O#@L5NY#F))QP]
M+)9.=.M-1`K,P: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?#XM/_N9O"WP6&I;/_I3_5*2?:2Z>>&FX_6KK>MMEW/
MCM8&W;4;MID.^7XE#%<@2B1+VC(NS-(`(#[IBWL=2R]AYCA?T$4;A:^UG],9
MOR55ET-Y]U;W0(AW`C1$R0`1HS[2%UJ[Z]=(<GWV3JGYPS^69"F__O%`=^;Q
M%D^^T(L_9Y[0&[6NQV_2X4]C$OEBL"",5>6W8/$=#.&()01]/^07"OT`?_T,
M"<@/"/+MY%4)%1^4=]?#DQ%X>O&O1$%'=MUN&<FUWL`?/C9R#3JC]K6>#JER
B6#W2Y:TEQ684J\8<H_94H[FBTAS$DM%Z\=_4Y80:(C\`````
`
end

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: ascii

iQCVAwUBMz9tknD/+HJTpU/hAQHjZgQAhPHc5ysXCTYTVbGI4543WqPEpm2d+THE
+MzTSOJScCJ3ki78cHVtpMJ3xRhTF9lh8PX05dKV0UJYOai5QLARgtd7Dc1QxgyF
pnPHfaJBfij8AiA4QRc6uVknHja+JBlXzA+quWt0t4tivOqAGZw7nTJ0+8x1j5qi
qWvydubJoEo=
=8CMI
-----END PGP SIGNATURE-----


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

end of thread, other threads:[~1997-04-01  0:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-03-26 17:46 ksh autoloading Zefram
1997-03-27 18:15 ` Roderick Schertler
1997-03-27 18:36   ` Zefram
1997-03-27 18:57     ` Roderick Schertler
1997-03-27 19:11       ` Zefram
1997-04-01  0:08 Zefram

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