zsh-workers
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: A serious bug in execution – where to debug?
Date: Wed, 31 Jul 2019 00:32:59 +0200	[thread overview]
Message-ID: <CAN=4vMrudHprUE=xb+V7Y+3T6tZvs7wRAe7TbC-BK_Zv+sczUg@mail.gmail.com> (raw)
In-Reply-To: <49013421-774e-4389-a25d-680f1d97a8ef@www.fastmail.com>

On Wed, Jul 31, 2019 at 12:19 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>
> Roman Perepelitsa wrote on Tue, 30 Jul 2019 21:46 +00:00:
> > You should call `emulate -L zsh` from every functions that can be
> > called by any code other than yours. It's almost impossible to write
> > code that works the same way with all combinations of options. In my
> > public code I also unset aliases. These defensive measures reduce the
> > number of bug reports by *a lot*. People really seem to like creating
> > global aliases with single-letter names.
>
> z-sy-h also does 'emulate -L' and unsets aliases.

By the way, why does it deal with aliases manually instead of
`unsetopt aliases`?

>  I wonder if there
> should be a built-in way to do this, in order to make it easier to write
> plugins?  Perhaps a «source -U foo.zsh» syntax, as in autoload?

The only problem I have with `unsetopt aliases` is that it has to be
done before a function is parsed. This means using one of two
patterns:

1. Remember at the top of the file if `aliases` options is set, then
unset the option. At the bottom of the file, restore aliases.
2. Use two files. The first contains the real meet. The second has an
anonymous function with `emulate -L zsh && unsetopt alizes && source
first.zsh`.

The first is bound to sometimes fail to restore the options, which
causes catastrophic effects. The second requires two files makes
things a bit slower.

I use (2) with large files as it gives me the additional benefit of
being able to prevent extra loads of the file. The small file acts
like a header guard in C. Having the guarantee that my file is sourced
at most once gives many advantages.

> > I'll probably start calling `disable -f` for all builtins I use.
>
> I wonder if you might be throwing the baby out with the bathwater here.
> Aren't there legitimate use-cases for writing shadowing functions?  For
> example, what if somebody does «zle() { typeset -p funcstack >&2; zle "$@" }»
> for debugging purposes?

The flip side is that users often define functions with any name they
feel like and are none the wiser if they are shadowing some obscure
builtin your code needs. If you want to call the builtin, call the
builtin.

I'm on the fence on this issue. As long as I don't get too many bug
reports because of over-ambitious plugin managers, I'm fine. It does
get on my nerves sometimes though. If I could defend against functions
shadowing builtins easily, I would. I just don't know how. If
`builtin`, `disable`, `setopt`, `unsetopt`, `unset` and `unfunction`
are all hidden, escaping the sandbox is tricky.

Roman.

  reply	other threads:[~2019-07-30 22:34 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-30 17:00 Sebastian Gniazdowski
2019-07-30 17:05 ` Sebastian Gniazdowski
2019-07-30 17:41 ` Roman Perepelitsa
2019-07-30 17:55   ` Sebastian Gniazdowski
2019-07-30 18:12     ` Roman Perepelitsa
2019-07-30 18:16       ` Sebastian Gniazdowski
2019-07-30 18:22         ` Roman Perepelitsa
2019-07-30 18:53           ` Sebastian Gniazdowski
2019-07-30 19:23             ` Roman Perepelitsa
2019-07-30 19:34               ` Sebastian Gniazdowski
2019-07-30 19:41                 ` Roman Perepelitsa
2019-07-30 19:59                   ` Sebastian Gniazdowski
2019-07-30 20:08                     ` Roman Perepelitsa
2019-07-30 20:38                       ` Sebastian Gniazdowski
2019-07-30 18:27 ` Bart Schaefer
2019-07-30 18:46   ` Sebastian Gniazdowski
2019-07-30 21:02     ` Roman Perepelitsa
2019-07-30 21:38       ` Sebastian Gniazdowski
2019-07-30 21:45         ` Roman Perepelitsa
2019-07-30 21:54           ` Sebastian Gniazdowski
2019-07-30 22:11             ` Roman Perepelitsa
2019-07-30 22:18           ` Daniel Shahaf
2019-07-30 22:32             ` Roman Perepelitsa [this message]
2019-07-31  1:30               ` Sebastian Gniazdowski
2019-07-31  7:23                 ` Roman Perepelitsa
2019-07-31 11:41                   ` Sebastian Gniazdowski
2019-07-31 12:40                     ` Roman Perepelitsa
2019-07-31 13:10                       ` Sebastian Gniazdowski
2019-07-31 13:34                         ` Roman Perepelitsa
2019-07-31 13:40                           ` Sebastian Gniazdowski
2019-07-31 14:11                             ` Roman Perepelitsa
2019-07-31 17:56                               ` Sebastian Gniazdowski
2019-07-31  1:42               ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN=4vMrudHprUE=xb+V7Y+3T6tZvs7wRAe7TbC-BK_Zv+sczUg@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).