= !NILP (BVAR (current_buffer, enable_multibyte_characters)); \
Lisp_Object original = printcharfun; \
record_unwind_current_buffer (); \
+ specbind(Qprint__unreadable_callback_buffer, Fcurrent_buffer ()); \
if (NILP (printcharfun)) printcharfun = Qt; \
if (BUFFERP (printcharfun)) \
{ \
infinite recursion in the function called. */
Lisp_Object func = Vprint_unreadable_function;
specbind (Qprint_unreadable_function, Qnil);
+
+ /* If we're being called from `prin1-to-string' or the like,
+ we're now in the secret " prin1" buffer. This can lead to
+ problems if, for instance, the callback function switches a
+ window to this buffer -- this will make Emacs segfault. */
+ if (!NILP (Vprint__unreadable_callback_buffer)
+ && Fbuffer_live_p (Vprint__unreadable_callback_buffer))
+ {
+ record_unwind_current_buffer ();
+ set_buffer_internal (XBUFFER (Vprint__unreadable_callback_buffer));
+ }
Lisp_Object result = CALLN (Ffuncall, func, obj,
escapeflag? Qt: Qnil);
unbind_to (count, Qnil);
Vprint_unreadable_function = Qnil;
DEFSYM (Qprint_unreadable_function, "print-unreadable-function");
+ DEFVAR_LISP ("print--unreadable-callback-buffer",
+ Vprint__unreadable_callback_buffer,
+ doc: /* Dynamically bound to indicate current buffer. */);
+ Vprint__unreadable_callback_buffer = Qnil;
+ DEFSYM (Qprint__unreadable_callback_buffer,
+ "print--unreadable-callback-buffer");
+
defsubr (&Sflush_standard_output);
/* Initialized in print_create_variable_mapping. */
(should (equal (butlast l n)
(subr-tests--butlast-ref l n))))))
+(ert-deftest test-print-unreadable-function-buffer ()
+ (with-temp-buffer
+ (let ((current (current-buffer))
+ callback-buffer)
+ (let ((print-unreadable-function
+ (lambda (_object _escape)
+ (setq callback-buffer (current-buffer)))))
+ (prin1-to-string (make-marker)))
+ (should (eq current callback-buffer)))))
+
(provide 'subr-tests)
;;; subr-tests.el ends here