zsh-workers
 help / color / mirror / code / Atom feed
* Re: something strange with compset and/or _normal
  1999-06-10 15:20 something strange with compset and/or _normal Sven Wischnowsky
@ 1999-06-10 15:04 ` Peter Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 1999-06-10 15:04 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky wrote:
> A bug with the execution-optimisation patch that showed up when
> shell functions called themselves recursively.

Is it clear this can't happen with arguments to the exec*() functions,
which are handled by the same mechanism?  I presume no other type of shell
structure apart from functions can be running in two forms at the same
time, but I haven't quite followed how it works out.

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


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

* Re: something strange with compset and/or _normal
@ 1999-06-10 15:20 Sven Wischnowsky
  1999-06-10 15:04 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Sven Wischnowsky @ 1999-06-10 15:20 UTC (permalink / raw)
  To: zsh-workers


Andrej Borsenkow wrote:

> I try to complete after sudo; the relevant part (albeit clumsy) is
> 
> if [[ $cmd -gt 0 ]] && compset -n $cmd
> then
>     _normal
> 
> where ``cmd'' is position of command to execute and is computed somewhere
> else.
> 
> Unfortunately, that is what I get in log:
> + [[ -z _umount ]]
> + _sudo

A bug with the execution-optimisation patch that showed up when
shell functions called themselves recursively.

Bye
 Sven

diff -u os/exec.c Src/exec.c
--- os/exec.c	Tue Jun  8 15:23:06 1999
+++ Src/exec.c	Thu Jun 10 17:15:35 1999
@@ -1955,7 +1954,6 @@
 
 	    if (is_shfunc) {
 		/* It's a shell function */
-		LinkList tmpa = cmd->args;
 		int ofl = cmd->flags;
 
 #ifdef PATH_DEV_FD
@@ -1968,10 +1966,8 @@
 		if (subsh_close >= 0)
 		    zclose(subsh_close);
 		subsh_close = -1;
-		cmd->args = args;
 		cmd->flags = flags;
-		execshfunc(cmd, (Shfunc) hn);
-		cmd->args = tmpa;
+		execshfunc(cmd, (Shfunc) hn, args);
 		cmd->flags = ofl;
 #ifdef PATH_DEV_FD
 		for (i = 10; i <= max_zsh_fd; i++)
@@ -2775,7 +2771,7 @@
 
 /**/
 static void
-execshfunc(Cmd cmd, Shfunc shf)
+execshfunc(Cmd cmd, Shfunc shf, LinkList args)
 {
     LinkList last_file_list = NULL;
 
@@ -2793,9 +2789,9 @@
     if (isset(XTRACE)) {
 	LinkNode lptr;
 	fprintf(stderr, "%s", prompt4 ? prompt4 : prompt4);
-	if (cmd->args)
-	    for (lptr = firstnode(cmd->args); lptr; incnode(lptr)) {
-		if (lptr != firstnode(cmd->args))
+	if (args)
+	    for (lptr = firstnode(args); lptr; incnode(lptr)) {
+		if (lptr != firstnode(args))
 		    fputc(' ', stderr);
 		fprintf(stderr, "%s", (char *)getdata(lptr));
 	    }
@@ -2803,7 +2799,7 @@
 	fflush(stderr);
     }
 
-    doshfunc(shf->nam, shf->funcdef, cmd->args, shf->flags, 0);
+    doshfunc(shf->nam, shf->funcdef, args, shf->flags, 0);
 
     if (!list_pipe)
 	deletefilelist(last_file_list);

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* Re: something strange with compset and/or _normal
  1999-06-11  6:57 Sven Wischnowsky
@ 1999-06-11 11:09 ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 1999-06-11 11:09 UTC (permalink / raw)
  To: zsh-workers

On Jun 11,  8:57am, Sven Wischnowsky wrote:
} Subject: Re: something strange with compset and/or _normal

The following hunk failed for me because I have `zlong val = 0;' in
execfor() from one of Peter's previous patches.  Just make the obvious
edits by hand.

} diff -u os/loop.c Src/loop.c
} --- os/loop.c	Fri Jun 11 08:47:41 1999
} +++ Src/loop.c	Fri Jun 11 08:49:15 1999
} @@ -47,15 +47,13 @@
}  
}  /**/
}  int
} -execfor(Cmd cmd)
} +execfor(Cmd cmd, LinkList args, int flags)
}  {
}      Forcmd node;
}      char *str;
}      int val = 0;
} -    LinkList args;
}  
}      node = cmd->u.forcmd;
} -    args = cmd->args;
}      if (node->condition) {
}  	str = dupstring(node->name);
}  	singsub(&str);

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: something strange with compset and/or _normal
@ 1999-06-11  6:57 Sven Wischnowsky
  1999-06-11 11:09 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Sven Wischnowsky @ 1999-06-11  6:57 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> Sven Wischnowsky wrote:
> > A bug with the execution-optimisation patch that showed up when
> > shell functions called themselves recursively.
> 
> Is it clear this can't happen with arguments to the exec*() functions,
> which are handled by the same mechanism?

No it isn't. I was aware of this yesterday but first wanted to see if
there is a better way than the obvious `pass args and flags to all
exec* functions'. I didn't found one.

The patch also removes the /*--- comments. I investigated the code
some more and am pretty sure that those set-to-NULLs didn't have an
effect. The one in lex.c seems to work (and yytext is only used in
very few places -- the function where it is set and yyerror()).
The one in stripkshdef() was probably wrong -- the test weren't really 
different so I just put in the old test again.

Bye
 Sven

diff -u os/exec.c Src/exec.c
--- os/exec.c	Fri Jun 11 08:47:39 1999
+++ Src/exec.c	Fri Jun 11 08:47:54 1999
@@ -297,12 +297,12 @@
 
 /**/
 static int
-execcursh(Cmd cmd)
+execcursh(Cmd cmd, LinkList args, int flags)
 {
     if (!list_pipe)
 	deletejob(jobtab + thisjob);
-    execlist(cmd->u.list, 1, cmd->flags & CFLAG_EXEC);
-    /*---- where was this used? cmd->u.list = NULL; */
+    execlist(cmd->u.list, 1, flags & CFLAG_EXEC);
+
     return lastval;
 }
 
@@ -1011,10 +1011,9 @@
 	    strcpy(list_pipe_text, getjobtext((void *) pline->left));
 	else
 	    list_pipe_text[0] = '\0';
-    if (pline->type == END) {
+    if (pline->type == END)
 	execcmd(pline->left, input, output, how, last1 ? 1 : 2);
-	/*---- where was this used? pline->left = NULL; */
-    } else {
+    else {
 	int old_list_pipe = list_pipe;
 
 	mpipe(pipes);
@@ -1051,7 +1050,6 @@
 	    subsh_close = pipes[0];
 	    execcmd(pline->left, input, pipes[1], how, 0);
 	}
-	/*---- where was this used? pline->left = NULL; */
 	zclose(pipes[1]);
 	if (pline->right) {
 	    /* if another execpline() is invoked because the command is *
@@ -1910,25 +1908,15 @@
 	if (is_exec)
 	    entersubsh(how, type != SUBSH ? 2 : 1, 1);
 	if (type >= CURSH) {
-	    static int (*func[]) _((Cmd)) = {
+	    static int (*func[]) _((Cmd, LinkList, int)) = {
 		execcursh, exectime, execfuncdef, execfor, execwhile,
 		execrepeat, execif, execcase, execselect, execcond,
 		execarith, execautofn
 	    };
-	    int ofl = cmd->flags;
 
 	    if (last1 == 1)
 		flags |= CFLAG_EXEC;
-	    cmd->flags = flags;
-	    if (type != AUTOFN) {
-		LinkList tmpa = cmd->args;
-
-		cmd->args = args;
-		lastval = (func[type - CURSH]) (cmd);
-		cmd->args = tmpa;
-	    } else
-		lastval = (func[type - CURSH]) (cmd);
-	    cmd->flags = ofl;
+	    lastval = (func[type - CURSH]) (cmd, args, flags);
 	} else if (is_builtin || is_shfunc) {
 	    LinkList restorelist = 0, removelist = 0;
 	    /* builtin or shell function */
@@ -1954,7 +1942,6 @@
 
 	    if (is_shfunc) {
 		/* It's a shell function */
-		int ofl = cmd->flags;
 
 #ifdef PATH_DEV_FD
 		int i;
@@ -1966,9 +1953,7 @@
 		if (subsh_close >= 0)
 		    zclose(subsh_close);
 		subsh_close = -1;
-		cmd->flags = flags;
 		execshfunc(cmd, (Shfunc) hn, args);
-		cmd->flags = ofl;
 #ifdef PATH_DEV_FD
 		for (i = 10; i <= max_zsh_fd; i++)
 		    if (fdtable[i] > 1)
@@ -2672,7 +2657,7 @@
 
 /**/
 static int
-execcond(Cmd cmd)
+execcond(Cmd cmd, LinkList args, int flags)
 {
     int stat;
     if (isset(XTRACE)) {
@@ -2692,15 +2677,15 @@
 
 /**/
 static int
-execarith(Cmd cmd)
+execarith(Cmd cmd, LinkList args, int flags)
 {
     char *e;
     zlong val = 0;
 
     if (isset(XTRACE))
 	fprintf(stderr, "%s((", prompt4 ? prompt4 : "");
-    if (cmd->args)
-	while ((e = (char *) ugetnode(cmd->args))) {
+    if (args)
+	while ((e = (char *) ugetnode(args))) {
 	    if (isset(XTRACE))
 		fprintf(stderr, " %s", e);
 	    val = matheval(e);
@@ -2717,7 +2702,7 @@
 
 /**/
 static int
-exectime(Cmd cmd)
+exectime(Cmd cmd, LinkList args, int flags)
 {
     int jb;
 
@@ -2735,15 +2720,15 @@
 
 /**/
 static int
-execfuncdef(Cmd cmd)
+execfuncdef(Cmd cmd, LinkList args, int flags)
 {
     Shfunc shf;
     char *s;
     int signum;
 
-    if (cmd->args) {
+    if (args) {
 	PERMALLOC {
-	    while ((s = (char *) ugetnode(cmd->args))) {
+	    while ((s = (char *) ugetnode(args))) {
 		shf = (Shfunc) zalloc(sizeof *shf);
 		shf->funcdef = (List) dupstruct(cmd->u.list);
 		shf->flags = 0;
@@ -2813,7 +2798,7 @@
 
 /**/
 static int
-execautofn(Cmd cmd)
+execautofn(Cmd cmd, LinkList args, int flags)
 {
     Shfunc shf = cmd->u.autofn->shf;
     List l = getfpfunc(shf->nam);
@@ -3056,10 +3041,9 @@
     c = p->left;
     if (c->type != FUNCDEF || c->flags ||
 	(c->redir && nonempty(c->redir)) || (c->vars && nonempty(c->vars)) ||
-        /*---- is this ok? the test /was/ different, i think it was wrong */
-	(c->args && (empty(c->args) ||
-		     lastnode(c->args) != firstnode(c->args) ||
-		     strcmp(name, peekfirst(c->args)))))
+	!c->args || empty(c->args) ||
+	lastnode(c->args) != firstnode(c->args) ||
+	strcmp(name, peekfirst(c->args)))
 	return l;
     return c->u.list;
 }
diff -u os/lex.c Src/lex.c
--- os/lex.c	Fri Jun 11 08:47:41 1999
+++ Src/lex.c	Fri Jun 11 08:47:55 1999
@@ -1393,10 +1393,7 @@
 
     if (!tokstr) {
 	yytext = tokstrings[tok];
-	/*---- is this really needed? should it be?
-	if (yytext)
-	    yytext = dupstring(yytext);
-	*/
+
 	return 0;
     }
 
diff -u os/loop.c Src/loop.c
--- os/loop.c	Fri Jun 11 08:47:41 1999
+++ Src/loop.c	Fri Jun 11 08:49:15 1999
@@ -47,15 +47,13 @@
 
 /**/
 int
-execfor(Cmd cmd)
+execfor(Cmd cmd, LinkList args, int flags)
 {
     Forcmd node;
     char *str;
     int val = 0;
-    LinkList args;
 
     node = cmd->u.forcmd;
-    args = cmd->args;
     if (node->condition) {
 	str = dupstring(node->name);
 	singsub(&str);
@@ -99,7 +97,7 @@
 	    setsparam(node->name, ztrdup(str));
 	}
 	execlist(node->list, 1,
-		 (cmd->flags & CFLAG_EXEC) && args && empty(args));
+		 (flags & CFLAG_EXEC) && args && empty(args));
 	if (breaks) {
 	    breaks--;
 	    if (breaks || !contflag)
@@ -127,18 +125,16 @@
 
 /**/
 int
-execselect(Cmd cmd)
+execselect(Cmd cmd, LinkList args, int flags)
 {
     Forcmd node;
     char *str, *s;
-    LinkList args;
     LinkNode n;
     int i;
     FILE *inp;
     size_t more;
 
     node = cmd->u.forcmd;
-    args = cmd->args;
     if (!node->inflag) {
 	char **x;
 
@@ -274,7 +270,7 @@
 
 /**/
 int
-execwhile(Cmd cmd)
+execwhile(Cmd cmd, LinkList args, int flags)
 {
     struct whilecmd *node;
     int olderrexit, oldval;
@@ -315,16 +311,16 @@
 
 /**/
 int
-execrepeat(Cmd cmd)
+execrepeat(Cmd cmd, LinkList args, int flags)
 {
     int count;
 
     lastval = 0;
-    if (!cmd->args || empty(cmd->args) || nextnode(firstnode(cmd->args))) {
+    if (!args || empty(args) || nextnode(firstnode(args))) {
 	zerr("bad argument for repeat", NULL, 0);
 	return 1;
     }
-    count = atoi(peekfirst(cmd->args));
+    count = atoi(peekfirst(args));
     pushheap();
     loops++;
     while (count--) {
@@ -348,7 +344,7 @@
 
 /**/
 int
-execif(Cmd cmd)
+execif(Cmd cmd, LinkList args, int flags)
 {
     struct ifcmd *node;
     int olderrexit;
@@ -371,7 +367,7 @@
     noerrexit = olderrexit;
 
     if (*t)
-	execlist(*t, 1, cmd->flags & CFLAG_EXEC);
+	execlist(*t, 1, flags & CFLAG_EXEC);
     else
 	lastval = 0;
 
@@ -380,7 +376,7 @@
 
 /**/
 int
-execcase(Cmd cmd)
+execcase(Cmd cmd, LinkList args, int flags)
 {
     struct casecmd *node;
     char *word;
@@ -402,7 +398,7 @@
 	    singsub(&pat);
 	    if (matchpat(word, pat)) {
 		do {
-		    execlist(*l++, 1, **p == ';' && (cmd->flags & CFLAG_EXEC));
+		    execlist(*l++, 1, **p == ';' && (flags & CFLAG_EXEC));
 		} while(**p++ == '&' && *p);
 		break;
 	    }

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* something strange with compset and/or _normal
@ 1999-06-10 14:49 Andrej Borsenkow
  0 siblings, 0 replies; 5+ messages in thread
From: Andrej Borsenkow @ 1999-06-10 14:49 UTC (permalink / raw)
  To: ZSH workers mailing list

I try to complete after sudo; the relevant part (albeit clumsy) is

if [[ $cmd -gt 0 ]] && compset -n $cmd
then
    _normal

where ``cmd'' is position of command to execute and is computed somewhere
else.

Unfortunately, that is what I get in log:

+ local comp
+ setopt localoptions nullglob rcexpandparam
+ unsetopt markdirs globsubst shwordsplit nounset ksharrays
+ compset -P 1 \=
+ [[ /t != */* ]]
+ ((  0  ))
+ set _complete _match
+ _complete
+ local comp name
+ [[ -n  ]]
+ comp=_first
+ [[ ! -z _first ]]
+ _first
+ ((  0  ))
+ [[ command == command ]]
+ _normal
+ local comp command cmd1 cmd2 pat val name i ret=1
+ command=sudo
+ [[ CURRENT -eq 1 ]]
+ [[ s == = ]]
+ [[ sudo == */* ]]
+ cmd1=sudo
+ cmd2=+ whence -p sudo
+ cmd2=/tools/bin/sudo
+ pat=zf*
+ val=_zftp
+ [[ sudo == zf* || /tools/bin/sudo == zf* ]]
+ name=sudo
+ comp=_sudo
+ [[ -z _sudo ]]
+ [[ -z _sudo ]]
+ [[ -z _sudo ]]
+ _sudo
+ emulate -L zsh
+ local -i i=1 cmd=0
+ [[ 1 -lt 3 ]]
+ [[ 2 -gt 2 ]]
+ cmd=2
+ break
+ [[ 2 -gt 0 ]]
+ compset -n 2
+ _normal
+ local comp command cmd1 cmd2 pat val name i ret=1
+ command=umount
+ [[ CURRENT -eq 1 ]]
+ [[ u == = ]]
+ [[ umount == */* ]]
+ cmd1=umount
+ cmd2=+ whence -p umount
+ cmd2=/usr/sbin/umount
+ pat=zf*
+ val=_zftp
+ [[ umount == zf* || /usr/sbin/umount == zf* ]]
+ name=umount
+ comp=_umount
+ [[ -z _umount ]]
+ [[ -z _umount ]]
+ [[ -z _umount ]]
+ _sudo


Oops! Why is _sudo called instead of _umount?

/andrej


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

end of thread, other threads:[~1999-06-11 11:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-10 15:20 something strange with compset and/or _normal Sven Wischnowsky
1999-06-10 15:04 ` Peter Stephenson
  -- strict thread matches above, loose matches on Subject: below --
1999-06-11  6:57 Sven Wischnowsky
1999-06-11 11:09 ` Bart Schaefer
1999-06-10 14:49 Andrej Borsenkow

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