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

From: Eli Zaretskii <[email-masked]>
Date: Tue, 26 Jul 2022 16:12:11 +0300

> From: Lars Ingebrigtsen <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Tue, 26 Jul 2022 14:44:31 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > unwind_protect?
> 
> Where would the unwind_protect be?
> 
> The problem is here:
> 
>   if (!NILP (Vprint_unreadable_function)
>       && FUNCTIONP (Vprint_unreadable_function))
>     {
>       specpdl_ref count = SPECPDL_INDEX ();
>       /* Bind `print-unreadable-function' to nil to avoid accidental
> 	 infinite recursion in the function called.  */
>       Lisp_Object func = Vprint_unreadable_function;
>       specbind (Qprint_unreadable_function, Qnil);
>       Lisp_Object result = CALLN (Ffuncall, func, obj,
> 				  escapeflag? Qt: Qnil);
> 
> We need to switch back to the original buffer before that Ffuncall, but
> we don't know what the original function was -- it's just stored in a
> local variable in prin1(-to-string).

I'm confused: "original function" or "original buffer"?

The original buffer is given by current_buffer before you call the
function which could change that, and the unwind_protect call should
be before calling that function.

But you already know all that, so I'm afraid I'm missing something
here.