Subject: Re: bug#65095: 30.0.50; thread_check_current_buffer

From: Eli Zaretskii <[email-masked]>
Date: Sat, 05 Aug 2023 16:11:47 +0300

> From: Helmut Eller <[email-masked]>
> Date: Sat, 05 Aug 2023 14:51:26 +0200
> 
> This test fails
> 
> (ert-deftest tmp-buf ()
>   (let (buf)
>     (with-temp-buffer
>       (setq buf (current-buffer))
>       (make-thread (lambda ())))
>     (should-not (buffer-live-p buf))))
> 
> when executed with
> 
>   emacs -Q --batch -l tmp-buf.el -f ert-run-tests-batch-and-exit
> 
> The reason seems to be, that thread_check_current_buffer returns true
> and hence kill_buffer simply returns without doing anything.
> 
> I don't understand why this check is there

How would kill-buffer know whether it's okay to kill a buffer that is
current in another thread?  When we kill the current buffer in the
current thread, we do quite a bit of juggling to replace it with some
other, and punt if not possible.  We also "do nothing" if the buffer
to be killed is the currently active minibuffer or the sole visible
buffer.  So this "do nothing" in this case is not without precedent,
and cannot be just removed without having some non-trivial code in its
stead, right?

> E.g. ert--run-test-internal uses with-temp-buffer too, so if
> make-thread is used in a test, the temporary buffers will hang around
> and pile up.

The tests should arrange for deleting the buffer when no longer
needed.  The simplest is to have the thread kill its current buffer
before it (the thread) exits.