[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unwind-protect and inhibit-quit

From: Eli Zaretskii
Subject: Re: unwind-protect and inhibit-quit
Date: Fri, 16 Jul 2021 10:18:59 +0300

> From: Felix Dietrich <>
> 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

> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]