all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: unwind-protect and inhibit-quit
Date: Fri, 16 Jul 2021 10:18:59 +0300	[thread overview]
Message-ID: <83eeby680s.fsf@gnu.org> (raw)
In-Reply-To: <875yxbr4lr.fsf@sperrhaken.name> (message from Felix Dietrich on Thu, 15 Jul 2021 17:14:56 +0200)

> From: Felix Dietrich <felix.dietrich@sperrhaken.name>
> Date: Thu, 15 Jul 2021 17:14:56 +0200
> 
> In the last paragraph [2], the description of the second example mentions a
> race condition between the assignment of the “ftp-setup-buffer”
> functionʼs return value to the variable “process” and the user sending a
> quit signal (C-g).  Does the first example suffer from the same issue in
> itʼs assignment to the “buffer” variable?

Yes.  But leaving an unused Emacs buffer around is a much less serious
issue than leaving a zombie process around.  We even have a command
which would kill such unused buffers from time to time -- see
midnight.el.

> That paragraph also mentions that “there is no easy way to fix this
> bug”.  Is that statement still true or can this issue be resolved by
> setting “inhibit-quit” in current Emacs versions:

You could use inhibit-quit, but that is generally a bad idea from the
UI point of view, when invoking potentially long-running functions:
you are preventing the user from interrupting that long function.  For
example, suppose the FTP command stalls for some reason.

> The first example has the “unwind-protect” form nested inside
> “with-current-buffer”; this leaves a window where the buffer is both
> created and assigned to the variable “buffer” but not protected from
> being left alive in case of a quit (or, in more elaborated uses, an
> error).  Shouldn’t it, therefore, be the other way around:
> “unwind-protect” wrapping “with-current-buffer”?

If that can be done, yes, it's better.

>         (and buffer (kill-buffer buffer))))

This should be

  (and (bufferp buffer) (kill-buffer buffer))

> There also seems to be an issue in the first example with modifying and
> killing a potentially already existing buffer " *temp*", which could be
> avoided, I believe, by using “generate-new-buffer”:

Yes.  (These are simplified examples, not industry-strength programs.)

> Does “generate-new-buffer” make the same guarantee as
> “get-buffer-create” that it will never return nil?  At least
> “generate-new-buffer” is implemented with “get-buffer-create”.

So you already have your answer, right?



  reply	other threads:[~2021-07-16  7:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15 15:14 unwind-protect and inhibit-quit Felix Dietrich
2021-07-16  7:18 ` Eli Zaretskii [this message]
2021-07-16  8:10   ` Thibaut Verron
2021-07-16 11:19     ` Eli Zaretskii
2021-07-16 14:46       ` Felix Dietrich
2021-07-16 14:56         ` Felix Dietrich
2021-07-16 15:00     ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-07-16 20:01       ` Thibaut Verron
2021-07-16 20:06         ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-07-16 21:30       ` Felix Dietrich
2021-07-16 21:37         ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-07-17 11:52           ` Felix Dietrich
2021-07-17  6:20         ` Eli Zaretskii
2021-07-17 15:46           ` Felix Dietrich
2021-07-17 16:34             ` Eli Zaretskii

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=83eeby680s.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=help-gnu-emacs@gnu.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.