zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "Mark J. Reed" <markjreed@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: mapfile and unset: Does this actually work?
Date: Sun, 4 Feb 2024 15:13:38 -0800	[thread overview]
Message-ID: <CAH+w=7Z9LcQTUa8qgru7wz9uwHshM+PVbqw_x_g04srwqyp9Jg@mail.gmail.com> (raw)
In-Reply-To: <CAA=-s3zrbuW_oggw84EcyCFcuZTzte+X990a=usqwQ+cUv0Rxg@mail.gmail.com>

On Sun, Feb 4, 2024 at 10:04 AM Mark J. Reed <markjreed@gmail.com> wrote:
>
> I take that back. If the file is nonempty, then the file is deleted. If the file is empty, then it's not. So it seems to be an conflation of unset and empty in the mapfile logic.

Aha.  In the "get" method from the gsu struct:

    /* Set u.str to contents of file given by name */
    if ((contents = get_contents(pm->node.nam)))
        pm->u.str = contents;
    else {
        pm->u.str = "";
        pm->node.flags |= PM_UNSET;
    }

So an empty file always appears to [already] be unset, e.g.

 % touch empty
 % zmodload zsh/mapfile
 % print ${+mapfile[empty]}
 0

This in turn appears to be because get_contents() doesn't distinguish
a file it can't open from one whose contents it can't read.  More
specifically, mmap() on an empty file returns -1.

The unset logic in mapfile.c is never called because the parameter is
already marked unset.

Perhaps this is more suited for the BUGS file than for an immediate repair.


      reply	other threads:[~2024-02-04 23:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22  2:05 Bart Schaefer
2024-01-22  3:25 ` Bart Schaefer
2024-02-04  4:24 ` Bart Schaefer
2024-02-04 17:57   ` Mark J. Reed
2024-02-04 18:04     ` Mark J. Reed
2024-02-04 23:13       ` Bart Schaefer [this message]

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='CAH+w=7Z9LcQTUa8qgru7wz9uwHshM+PVbqw_x_g04srwqyp9Jg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=markjreed@gmail.com \
    --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).