Subject: bug#56773: 29.0.50; (readablep UNREADABLE) causes strange things

From: Lars Ingebrigtsen <[email-masked]>
Date: Tue, 26 Jul 2022 14:31:19 +0200

Michael Heerdegen <[email-masked]> writes:

> (progn (readablep (current-window-configuration))
>        (current-buffer))
> ==> #<buffer  prin1>
>
> After evaluating such a `readablep' call, weird things can happen
> because of this buffer being current.  I tried to actually display that
> buffer and the window I got looked quite funny, one second later Emacs
> had crashed.

Oops.

The problem is trivial to fix in `unreadablep' (just smack a
`save-excursion' in there), but I think this should be fixed in a better
way.  The problem is that PRINTPREPARE sets the current buffer to the
super-duper secret buffer Vprin1_to_string_buffer (i.e., " prin1"), and
we should restore the real buffer before calling
`print-unreadable-function' in `print_vectorlike'.

But which buffer that was doesn't seem to be available at that point --
it's just stored in

#define PRINTPREPARE							\
   struct buffer *old = current_buffer;					\

So we'd need to store that in a way we can access it later, but I'm not
sure where/how it'd make the most sense to do so...  Any ideas?

Meanwhile I've pushed a failing test for this to the trunk.