zsh-workers
 help / color / mirror / code / Atom feed
* setopt localfunctions, and two bugs with disable?
@ 1996-11-03  9:44 Bart Schaefer
  1996-11-03 22:52 ` Zoltan Hidvegi
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Schaefer @ 1996-11-03  9:44 UTC (permalink / raw)
  To: zsh-workers

On Nov 3, 12:53am, I wrote:
} 
} (Aside #2:  Does anybody wish there were an equivalent of "localoptions"
} that applied to functions and aliases, so that autoloads could blow away
} all the possible screwy redefinitions of builtins from their environment,
} yet have them magically restored when the function exits?)

Some thoughts that occur to me:

1.  One can of course use `disable -fm \*` and `disable -am \*`.  This
    requires that you remember to `enable -fm \*` etc. before returning,
    and doesn't provide for local redefinition of functions.  (BTW, I
    think there are some bugs in `disable -fm`.  See below.)

2.  It's difficult to make this work for aliases, because they're applied
    at lex time.  You can play some sneaky games with "eval" or "autoload"
    to defer lexing, but I'm not sure it's worth the effort.

3.  A possible implementation is to save and restore the function hash
    table, under control of a "localfunctions" option, exactly as the
    options array is saved and restored under control of "localoptions",
    upon every function entry/exit.  Doing so efficiently might be hard.
    (The options array is saved/restored on every call, no matter what
    the current setting of localoptions.  It occurs to me that there is
    probably a more efficient way to handle *that*, too.)

4.  Another possible implementation is to temporarily switch the order
    in which the builtin and function hash tables are searched.  That
    would mask all functions that have the same names as builtins, but
    leave other functions available.  However, it doesn't permit local
    redefinition of functions without loss of the original definitions,
    and it doesn't provide for local overrides of builtins (maybe some
    further tricks with "disable" would solve that).

Anyone else have thoughts on this?

The bugs in disable that I mentioned:

zagzig[440] functions
	(... lots of output suppressed ...)
undefined work () { }
undefined xvi () { }
undefined zed () { }
undefined zfind () { }
undefined zlook () { }
undefined zm () { }
	(... more output suppressed ...)
zagzig[441] disable -fm \*
zagzig[442] functions
undefined xvi () { }
zagzig[443] enable -fm \*
zagzig[444] functions
	(... same output as history 440 ...)
zagzig[445]

How did `xvi' survive through the "disable" command?

Also, the shell in which I performed the above actions appears to have
silently exited (and without saving history) upon the next expiration of
TMOUT.  I suspect that `disable -fm \*` did something bad with respect
to my TRAPALRM() function and the associated signal handlers, or at least
that `enable -fm \*` failed to restore something.

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern


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

* Re: setopt localfunctions, and two bugs with disable?
  1996-11-03  9:44 setopt localfunctions, and two bugs with disable? Bart Schaefer
@ 1996-11-03 22:52 ` Zoltan Hidvegi
  0 siblings, 0 replies; 2+ messages in thread
From: Zoltan Hidvegi @ 1996-11-03 22:52 UTC (permalink / raw)
  To: schaefer; +Cc: zsh-workers

> zagzig[440] functions
> 	(... lots of output suppressed ...)
> undefined work () { }
> undefined xvi () { }
> undefined zed () { }
> undefined zfind () { }
> undefined zlook () { }
> undefined zm () { }
> 	(... more output suppressed ...)
> zagzig[441] disable -fm \*
> zagzig[442] functions
> undefined xvi () { }
> zagzig[443] enable -fm \*
> zagzig[444] functions
> 	(... same output as history 440 ...)
> zagzig[445]
> 
> How did `xvi' survive through the "disable" command?

Please try to investigate it further so that I could reproduce this bug.

> Also, the shell in which I performed the above actions appears to have
> silently exited (and without saving history) upon the next expiration of
> TMOUT.  I suspect that `disable -fm \*` did something bad with respect
> to my TRAPALRM() function and the associated signal handlers, or at least
> that `enable -fm \*` failed to restore something.

You are right, disabling a TRAP functions really removes the function.  The
patch below is a fix for that.  If a disable TRAPxxx function is enabled
the currently set trap with the trap builtin is replaced by the function.

The fix is not very elegant but it seems to work.

Zoltan

*** Src/hashtable.c	1996/11/02 22:47:53	3.1.0.2
--- Src/hashtable.c	1996/11/03 22:38:17
***************
*** 698,705 ****
  disableshfuncnode(HashNode hn, int flags)
  {
      hn->flags |= DISABLED;
!     if (!strncmp(hn->nam, "TRAP", 4))
! 	unsettrap(getsignum(hn->nam + 4));
  }
  
  /* Re-enable an entry in the shell function hash table.  *
--- 698,709 ----
  disableshfuncnode(HashNode hn, int flags)
  {
      hn->flags |= DISABLED;
!     if (!strncmp(hn->nam, "TRAP", 4)) {
! 	int signum = getsignum(hn->nam + 4);
! 	sigtrapped[signum] &= ~ZSIG_FUNC;
! 	sigfuncs[signum] = NULL;
! 	unsettrap(signum);
!     }
  }
  
  /* Re-enable an entry in the shell function hash table.  *


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

end of thread, other threads:[~1996-11-03 23:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-03  9:44 setopt localfunctions, and two bugs with disable? Bart Schaefer
1996-11-03 22:52 ` Zoltan Hidvegi

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