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

Re: trap for EXIT doesn't catch exit?



On Sep 18, 12:28pm, Peter Stephenson wrote:
> 
> Probably the correct thing to do here is to pop all the saved EXIT's off
> the stack of saved traps, executing them one by one, to simulate exiting
> the scope of each function in turn.  I'll wait to see if there are comments
> before I do that (further discussion should probably go to zsh-workers).

I don't think it's sufficient to simulate exiting the scopes, because the
traps have to execute as if they're in the scope where they were installed.
It may be necessary to actually unwind the stack; at least it's necessary
to call endparamscope() and endtrapscope() the correct number of times.

The problem is really with the overloading of the exit trap for both return
from a function and exit from the shell.  In bash, for example, the exit
trap is never called when a function returns, only when the shell exits.
On the other hand, bash doesn't have the notion of local traps; changing a
trap in a bash function changes it globally, and it is not restored when
the function returns.

We may want to bring this up on the shell@xxxxxxxxxxxxxxxx list.



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