zsh-workers
 help / color / mirror / code / Atom feed
* Re: EXIT trap executes too late?Re: stuff
@ 2002-06-02 18:10 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2002-06-02 18:10 UTC (permalink / raw)
  To: Zsh hackers list

Bart wrote:
> "The functions beginning `TRAP' may alternatively be defined with the
> trap builtin:  this may be preferable for some uses, as they are then
> run in the environment of the calling process, rather than in their own
> function environment."
> 
> That doesn't appear to be true for the EXIT trap:

You're missing this (second paragraph of the texinfo node Functions):

  Functions execute in the same process as the caller and share all files
  and present working directory with the caller.  A trap on EXIT set
  inside a function is executed after the function completes in the
  environment of the caller.

So `the environment of the calling process' in the first quotation is
the environment which called the function for which the exit trap is
set, not the function where the exit trap is defined.  So it's doing
it's job properly (and indeed it was to ensure this behaviour that I
tinkered with execsave()/execrestore()).  However, this is confusing
because of the way `environment of the caller' has two meanings and the
documentation could probably be clearer.

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-06-02 18:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-02 18:10 EXIT trap executes too late?Re: stuff Peter Stephenson

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