zsh-workers
 help / color / mirror / code / Atom feed
* Is PRINT_EXIT_VALUE supposed to work?
@ 2001-06-15 13:22 Peter Stephenson
  2001-06-24  4:06 ` PATCH: " Bart Schaefer
  0 siblings, 1 reply; 12+ messages in thread
From: Peter Stephenson @ 2001-06-15 13:22 UTC (permalink / raw)
  To: Zsh hackers list

I've never looked at this option until now, when I'm trying to write a test
for it.  It doesn't work with functions.

% setopt printexitvalue
% false
zsh: exit 1
% func(){ false; }
% func
%

It seems to come from csh, so we can more or less invent our own usage
model in cases like this.  But I don't think the above is good enough.

(I never used to use phrases like `usage model' when I was physicist.  Oh,
well.)

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* PATCH: Re: Is PRINT_EXIT_VALUE supposed to work?
  2001-06-15 13:22 Is PRINT_EXIT_VALUE supposed to work? Peter Stephenson
@ 2001-06-24  4:06 ` Bart Schaefer
  2001-07-03 17:13   ` Peter Stephenson
  0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2001-06-24  4:06 UTC (permalink / raw)
  To: Zsh hackers list

On Jun 15,  2:22pm, Peter Stephenson wrote:
} Subject: Is PRINT_EXIT_VALUE supposed to work?
}
} I've never looked at this option until now, when I'm trying to write a
} test for it.  It doesn't work with functions.

The simplest thing seems to be the patch below.  I don't see any reason
to print the exit value of a builtin before flushing the stdout of that
builtin (though I also don't know of any case where it matters that the
stdout of the builtin gets flushed).

--- zsh-forge/current/Src/exec.c	Sat Jun 23 11:24:32 2001
+++ zsh-4.0/Src/exec.c	Sat Jun 23 20:53:45 2001
@@ -2288,9 +2288,6 @@
 #ifdef PATH_DEV_FD
 		closem(2);
 #endif
-		if (isset(PRINTEXITVALUE) && isset(SHINSTDIN) && lastval && !subsh) {
-		    fprintf(stderr, "zsh: exit %ld\n", (long)lastval);
-		}
 		fflush(stdout);
 		if (save[1] == -2) {
 		    if (ferror(stdout)) {
@@ -2299,6 +2296,10 @@
 		    }
 		} else
 		    clearerr(stdout);
+	    }
+	    if (isset(PRINTEXITVALUE) && isset(SHINSTDIN) &&
+		lastval && !subsh) {
+		fprintf(stderr, "zsh: exit %ld\n", (long)lastval);
 	    }
 
 	    if (do_exec) {

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: PATCH: Re: Is PRINT_EXIT_VALUE supposed to work?
  2001-06-24  4:06 ` PATCH: " Bart Schaefer
@ 2001-07-03 17:13   ` Peter Stephenson
  2001-07-03 17:46     ` Bart Schaefer
  2001-07-08 15:19     ` Bart Schaefer
  0 siblings, 2 replies; 12+ messages in thread
From: Peter Stephenson @ 2001-07-03 17:13 UTC (permalink / raw)
  To: Zsh hackers list

"Bart Schaefer" wrote:
> On Jun 15,  2:22pm, Peter Stephenson wrote:
> } Subject: Is PRINT_EXIT_VALUE supposed to work?
> }
> } I've never looked at this option until now, when I'm trying to write a
> } test for it.  It doesn't work with functions.
> 
> The simplest thing seems to be the patch below.

I've been a long time getting around to looking at this, but does this
really work?

  zsh -c 'setopt printexitvalue; fn() { false;}; fn'

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* Re: PATCH: Re: Is PRINT_EXIT_VALUE supposed to work?
  2001-07-03 17:13   ` Peter Stephenson
@ 2001-07-03 17:46     ` Bart Schaefer
  2001-07-08 15:19     ` Bart Schaefer
  1 sibling, 0 replies; 12+ messages in thread
From: Bart Schaefer @ 2001-07-03 17:46 UTC (permalink / raw)
  To: Peter Stephenson, Zsh hackers list

On Jul 3,  6:13pm, Peter Stephenson wrote:
} Subject: Re: PATCH: Re: Is PRINT_EXIT_VALUE supposed to work?
}
} > The simplest thing seems to be the patch below.
} 
} I've been a long time getting around to looking at this, but does this
} really work?
} 
}   zsh -c 'setopt printexitvalue; fn() { false;}; fn'

It works interactively:

schaefer<501> setopt printexitvalue; fn() { false;}; fn
zsh: correct 'fn' to 'fg' [nyae]? n
zsh: correct 'fn' to 'fg' [nyae]? n
zsh: exit 1

I don't know offhand why it doesn't work with `zsh -c', and I don't have
time to look at it just now ...

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: PATCH: Re: Is PRINT_EXIT_VALUE supposed to work?
  2001-07-03 17:13   ` Peter Stephenson
  2001-07-03 17:46     ` Bart Schaefer
@ 2001-07-08 15:19     ` Bart Schaefer
  2001-07-09  8:22       ` Sven Wischnowsky
  1 sibling, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2001-07-08 15:19 UTC (permalink / raw)
  To: Zsh hackers list

On Jul 3,  6:13pm, Peter Stephenson wrote:
} Subject: Re: PATCH: Re: Is PRINT_EXIT_VALUE supposed to work?
}
} I've been a long time getting around to looking at this, but does this
} really work?
} 
}   zsh -c 'setopt printexitvalue; fn() { false;}; fn'

This works for me now:

schaefer[652] Src/zsh -fc 'setopt printexitvalue; fn() { false;}; fn'
zsh: exit 1
schaefer[653] Src/zsh -fc 'fn() { false;}; fn'
schaefer[654] 

I can't see anything that might have changed since 15057 that would have
affected this, but there it is.

Meanwhile, I think I've spotted a bug in doshfunc().  Can someone explain
why the following (or something better that doesn't use `goto') is not
necessary?  (I won't commit it until I get second opinions from Sven and
PWS.)

Index: Src/exec.c
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Src/exec.c,v
retrieving revision 1.7
diff -c -r1.7 exec.c
--- exec.c	2001/06/28 08:40:25	1.7
+++ exec.c	2001/07/08 15:17:02
@@ -3359,9 +3359,7 @@
     if(++funcdepth > MAX_FUNCTION_DEPTH)
     {
         zerr("maximum nested function level reached", NULL, 0);
-	scriptname = oldscriptname;
-	popheap();
-	return;
+	goto undoshfunc;
     }
 #endif
     fstack.name = dupstring(name);
@@ -3382,14 +3380,14 @@
 		errflag = 1;
 	    else
 		lastval = 1;
-	    popheap();
-	    scriptname = oldscriptname;
-	    return;
+	    goto doneshfunc;
 	}
 	prog = shf->funcdef;
     }
     runshfunc(prog, wrappers, fstack.name);
+ doneshfunc:
     funcstack = fstack.prev;
+ undoshfunc:
 #ifdef MAX_FUNCTION_DEPTH
     --funcdepth;
 #endif


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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: PATCH: Re: Is PRINT_EXIT_VALUE supposed to work?
  2001-07-08 15:19     ` Bart Schaefer
@ 2001-07-09  8:22       ` Sven Wischnowsky
  2001-07-09 11:08         ` PATCH: doshfunc() Bart Schaefer
  0 siblings, 1 reply; 12+ messages in thread
From: Sven Wischnowsky @ 2001-07-09  8:22 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> ...
> 
> Meanwhile, I think I've spotted a bug in doshfunc().  Can someone explain
> why the following (or something better that doesn't use `goto') is not
> necessary?  (I won't commit it until I get second opinions from Sven and
> PWS.)

Whoa.  I think this was indeed wrong.


Bye
  Sven


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


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

* PATCH: doshfunc()
  2001-07-09  8:22       ` Sven Wischnowsky
@ 2001-07-09 11:08         ` Bart Schaefer
  2001-07-09 11:28           ` PATCH: doshfunc Sven Wischnowsky
  0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2001-07-09 11:08 UTC (permalink / raw)
  To: zsh-workers

On Jul 9, 10:22am, Sven Wischnowsky wrote:
} Subject: Re: PATCH: Re: Is PRINT_EXIT_VALUE supposed to work?
}
} Bart Schaefer wrote:
} 
} > Meanwhile, I think I've spotted a bug in doshfunc().
} 
} Whoa.  I think this was indeed wrong.

OK, here's a very slightly different patch, which I will commit later unless
somebody says I should not.  The first hunk just copies a bit of code from
line 3251 (big file) to another spot in the same function where it is also
needed.

Meanwhile, Sven:  When exactly does the EF_RUN flag get set?  That is, I
can see where it gets set in the code, but what set of circumstances does
that actually represent?  I tried several things with kshautoload and
zcompile but I couldn't get the `goto doneshfunc' below to be reached.  It
always complained instead at the zwarn in the first hunk.

Index: Src/exec.c
===================================================================
diff -c -r1.7 Src/exec.c
--- Src/exec.c	2001/06/28 08:40:25	1.7
+++ Src/exec.c	2001/07/09 07:07:10
@@ -3273,7 +3273,10 @@
 	    execode(prog, 1, 0);
 	    shf = (Shfunc) shfunctab->getnode(shfunctab, n);
 	    if (!shf || (shf->flags & PM_UNDEFINED)) {
+		/* We're not actually in the function; decrement locallevel */
+		locallevel--;
 		zwarn("%s: function not defined by file", n, 0);
+		locallevel++;
 		popheap();
 		return NULL;
 	    }
@@ -3359,9 +3362,7 @@
     if(++funcdepth > MAX_FUNCTION_DEPTH)
     {
         zerr("maximum nested function level reached", NULL, 0);
-	scriptname = oldscriptname;
-	popheap();
-	return;
+	goto undoshfunc;
     }
 #endif
     fstack.name = dupstring(name);
@@ -3382,15 +3383,15 @@
 		errflag = 1;
 	    else
 		lastval = 1;
-	    popheap();
-	    scriptname = oldscriptname;
-	    return;
+	    goto doneshfunc;
 	}
 	prog = shf->funcdef;
     }
     runshfunc(prog, wrappers, fstack.name);
+ doneshfunc:
     funcstack = fstack.prev;
 #ifdef MAX_FUNCTION_DEPTH
+ undoshfunc:
     --funcdepth;
 #endif
     if (retflag) {

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: PATCH: doshfunc
  2001-07-09 11:08         ` PATCH: doshfunc() Bart Schaefer
@ 2001-07-09 11:28           ` Sven Wischnowsky
  2001-07-09 16:11             ` Bart Schaefer
  0 siblings, 1 reply; 12+ messages in thread
From: Sven Wischnowsky @ 2001-07-09 11:28 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> ...
> 
> Meanwhile, Sven:  When exactly does the EF_RUN flag get set?  That is, I
> can see where it gets set in the code, but what set of circumstances does
> that actually represent?  I tried several things with kshautoload and
> zcompile but I couldn't get the `goto doneshfunc' below to be reached.  It
> always complained instead at the zwarn in the first hunk.

When using `autoload +X foo' on a function `foo' that has to be loaded
with ksh-style loading (because of `kshautoload' or `zcompile -k').


Bye
  Sven


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


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

* Re: PATCH: doshfunc
  2001-07-09 11:28           ` PATCH: doshfunc Sven Wischnowsky
@ 2001-07-09 16:11             ` Bart Schaefer
  2001-07-10  9:42               ` Sven Wischnowsky
  0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2001-07-09 16:11 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

On Jul 9,  1:28pm, Sven Wischnowsky wrote:
} Subject: Re: PATCH: doshfunc
}
} Bart Schaefer wrote:
} 
} > Meanwhile, Sven:  When exactly does the EF_RUN flag get set?
} 
} When using `autoload +X foo' on a function `foo' that has to be loaded
} with ksh-style loading (because of `kshautoload' or `zcompile -k').

Well, I just did this:

	echo 'bar() { print oops }' > foo
	setopt kshautoload
	FPATH=. autoload +X foo

and got no complaint at all.  And look what "functions foo" gives me:

	foo () {
		bar () {
			print oops
		}
		foo "$@"
	}

Something has magically supplied the `foo "$@"' at the end of the file!

So then I tried:

	unfunction foo
	zcompile -z foo
	mv foo bar
	FPATH=. autoload +X foo

And I get:

	foo () {
		bar () {
			print oops
		}
	}

Finally:

	unsetopt kshautoload
	unfunction foo
	mv bar foo
	zcompile -k foo
	mv foo bar
	FPATH=. autoload +X foo

and I get the magic `foo "$@"' again.

So I still can't reach the `goto doneshfunc'.

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: PATCH: doshfunc
  2001-07-09 16:11             ` Bart Schaefer
@ 2001-07-10  9:42               ` Sven Wischnowsky
  2001-07-10 16:06                 ` Bart Schaefer
  0 siblings, 1 reply; 12+ messages in thread
From: Sven Wischnowsky @ 2001-07-10  9:42 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> ...
> 
> Well, I just did this:
> 
> 	echo 'bar() { print oops }' > foo
> 	setopt kshautoload
> 	FPATH=. autoload +X foo
> 
> and got no complaint at all.  And look what "functions foo" gives me:
> 
> 	foo () {
> 		bar () {
> 			print oops
> 		}
> 		foo "$@"
> 	}
> 
> Something has magically supplied the `foo "$@"' at the end of the file!

It's eval_autoload() -- which you wrote this way in 8404 ;-)

> ...
> 
> So I still can't reach the `goto doneshfunc'.

You were asking about EF_RUN, that's what I tried to explain.

If you want that error message:

  % echo 'bar() { echo foobar }' >foo
  % zcompile -k foo
  % fpath=(. $fpath)
  % autoload foo
  % foo
  zsh: foo: function not defined by file

or:

  % rm -f foo.zwc
  % echo 'bar() { echo foobar }' >foo
  % setopt kshautoload
  % fpath=(. $fpath)
  % autoload foo
  % foo
  zsh: foo: function not defined by file


Bye
  Sven


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


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

* Re: PATCH: doshfunc
  2001-07-10  9:42               ` Sven Wischnowsky
@ 2001-07-10 16:06                 ` Bart Schaefer
  2001-07-11  7:18                   ` Sven Wischnowsky
  0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2001-07-10 16:06 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

On Jul 10, 11:42am, Sven Wischnowsky wrote:
} Subject: Re: PATCH: doshfunc
}
} Bart Schaefer wrote:
} 
} > 	foo () {
} > 		bar () {
} > 			print oops
} > 		}
} > 		foo "$@"
} > 	}
} > 
} > Something has magically supplied the `foo "$@"' at the end of the file!
} 
} It's eval_autoload() -- which you wrote this way in 8404 ;-)

No, it's not eval_autoload():

2122        if (!(shf->flags & PM_UNDEFINED))
(gdb) n
2125        if (shf->funcdef) {
(gdb) 
2126            freeeprog(shf->funcdef);
(gdb) 
2127            shf->funcdef = &dummy_eprog;
(gdb) 
2129        if (ops['X'] == 1) {
(gdb) 
2138        return !loadautofn(shf, (ops['k'] ? 2 : (ops['z'] ? 0 : 1)), 1);

The code that does `name "$@"' in eval_autoload() is assembling a command
to pass to bin_eval().  It doesn't append anything to the function def'n.

} > ...
} > 
} > So I still can't reach the `goto doneshfunc'.
} 
} You were asking about EF_RUN, that's what I tried to explain.

Right, I asked about EF_RUN because that error message is inside an
`if (prog->flags & EF_RUN)'.

} If you want that error message:
} 
}   % echo 'bar() { echo foobar }' >foo
}   % zcompile -k foo
}   % fpath=(. $fpath)
}   % autoload foo
}   % foo
}   zsh: foo: function not defined by file

That error message came from line 3253, not line 3381.

} or:
} 
}   % rm -f foo.zwc
}   % echo 'bar() { echo foobar }' >foo
}   % setopt kshautoload
}   % fpath=(. $fpath)
}   % autoload foo
}   % foo
}   zsh: foo: function not defined by file

Same thing there; the error is from line 3253.

Once again, what I want to know is how you reach line 3372 with EF_RUN in
the Eprog flags, and hence get the error from line 3381.

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: PATCH: doshfunc
  2001-07-10 16:06                 ` Bart Schaefer
@ 2001-07-11  7:18                   ` Sven Wischnowsky
  0 siblings, 0 replies; 12+ messages in thread
From: Sven Wischnowsky @ 2001-07-11  7:18 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> ...
> 
> The code that does `name "$@"' in eval_autoload() is assembling a command
> to pass to bin_eval().  It doesn't append anything to the function def'n.

Err, right, sorry.  I was far too hasty yesterday.  It's printshfuncnode().

> ...
> 
> That error message came from line 3253, not line 3381.

No, 3278 (in an unpatched exec.c).

> } or:
> } 
> }   % rm -f foo.zwc
> }   % echo 'bar() { echo foobar }' >foo
> }   % setopt kshautoload
> }   % fpath=(. $fpath)
> }   % autoload foo
> }   % foo
> }   zsh: foo: function not defined by file
> 
> Same thing there; the error is from line 3253.
> 
> Once again, what I want to know is how you reach line 3372 with EF_RUN in
> the Eprog flags, and hence get the error from line 3381.

You need an autoloaded function that unfunctions itself:

  % echo 'foo() { echo foo }' >foo
  % echo 'unfunction foo' >> foo
  % fpath=(. $fpath)
  % autoload +Xk foo
  % foo
  zsh: foo: function not defined by file

And this time it's the one on line 3381.


Bye
  Sven


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


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

end of thread, other threads:[~2001-07-11  7:20 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-15 13:22 Is PRINT_EXIT_VALUE supposed to work? Peter Stephenson
2001-06-24  4:06 ` PATCH: " Bart Schaefer
2001-07-03 17:13   ` Peter Stephenson
2001-07-03 17:46     ` Bart Schaefer
2001-07-08 15:19     ` Bart Schaefer
2001-07-09  8:22       ` Sven Wischnowsky
2001-07-09 11:08         ` PATCH: doshfunc() Bart Schaefer
2001-07-09 11:28           ` PATCH: doshfunc Sven Wischnowsky
2001-07-09 16:11             ` Bart Schaefer
2001-07-10  9:42               ` Sven Wischnowsky
2001-07-10 16:06                 ` Bart Schaefer
2001-07-11  7:18                   ` Sven Wischnowsky

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