because printing one char can relocate. */
static void
-print_string (Lisp_Object string, Lisp_Object printcharfun)
+print_string_1 (Lisp_Object string, Lisp_Object printcharfun, bool escape_nonascii)
{
if (EQ (printcharfun, Qt) || NILP (printcharfun))
{
ptrdiff_t chars;
- if (print_escape_nonascii)
+ if (escape_nonascii)
string = string_escape_byte8 (string);
if (STRING_MULTIBYTE (string))
chars = SCHARS (string);
- else if (! print_escape_nonascii
+ else if (! escape_nonascii
&& (EQ (printcharfun, Qt)
? ! NILP (BVAR (&buffer_defaults, enable_multibyte_characters))
: ! NILP (BVAR (current_buffer, enable_multibyte_characters))))
}
}
}
+
+static void
+print_string (Lisp_Object string, Lisp_Object printcharfun)
+{
+ print_string_1 (string, printcharfun, print_escape_nonascii);
+}
\f
DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0,
doc: /* Output character CHARACTER to stream PRINTCHARFUN.
}
else if (STRINGP (num))
{
- strout (SSDATA (num), SCHARS (num), SBYTES (num), printcharfun);
+ print_string_1 (num, printcharfun, false);
goto next_obj;
}
}
(should (eq callback-buffer buffer))
(should (equal str "tata"))))
+(ert-deftest test-print-number-realloc ()
+ ;; Test for bug#78590. Note that this may in rare cases crash unfixed
+ ;; Emacs versions.
+ (let ((print-circle t)
+ (print-number-table (make-hash-table))
+ (print-continuous-numbering t)
+ (str "yy")
+ (outstr ""))
+ (garbage-collect)
+ (ignore (make-string 100 ?a))
+ (puthash str (make-string 3 ?x) print-number-table)
+ (prin1 str
+ (lambda (c)
+ (setq outstr (concat outstr (string c)))
+ (garbage-collect)
+ (ignore (make-string 100 ?b))))
+ (should (equal outstr "xxx"))))
+
(provide 'print-tests)
;;; print-tests.el ends here