Subject: bug#75754: styled_format stack usage/GC protection

From: Eli Zaretskii <[email-masked]>
Date: Thu, 23 Jan 2025 22:32:31 +0200

> Date: Thu, 23 Jan 2025 19:32:44 +0000
> From: Pip Cet <[email-masked]>
> Cc: Paul Eggert <[email-masked]>, [email-masked]
> 
> So, assuming no one volunteers to write a specific test, let's close
> this bug.

I wrote a test:

diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index 9fff425..6da3c73 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -534,4 +534,14 @@ editfns-tests--before/after-change-functions
                             'utf-8 nil (current-buffer))
       (should (null (sanity-check-change-functions-errors))))))
 
+(ert-deftest editfns-tests-styled-print ()
+   (let* ((print-unreadable-function
+	   (lambda (&rest args)
+             (garbage-collect)
+             (make-string 100 ?Ā t)))
+          (str "\"[1] ĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀ\""))
+     (should (string=
+              (format "%S" (format "%S %S" [1] (symbol-function '+))) str))))
+
+
 ;;; editfns-tests.el ends here

It fails (after rebuilding with commit ed5067e689a5):

Test editfns-tests-styled-print backtrace:
  signal(ert-test-failed (((should (string= (format "%S" (format "%S %
  ert-fail(((should (string= (format "%S" (format "%S %S" [1] (symbol-
  (if (unwind-protect (setq value-602 (apply fn-600 args-601)) (setq f
  (let (form-description-604) (if (unwind-protect (setq value-602 (app
  (let ((value-602 'ert-form-evaluation-aborted-603)) (let (form-descr
  (let* ((fn-600 #'string=) (args-601 (condition-case err (list (forma
  (let* ((print-unreadable-function #'(lambda (&rest args) (garbage-co
  #f(lambda () [t] (let* ((print-unreadable-function #'...) (str "\"[1
  #f(compiled-function () #<bytecode 0x118aa52bef4d292f>)()
  handler-bind-1(#f(compiled-function () #<bytecode 0x118aa52bef4d292f
  ert--run-test-internal(#s(ert--test-execution-info :test #s(ert-test
  ert-run-test(#s(ert-test :name editfns-tests-styled-print :documenta
  ert-run-or-rerun-test(#s(ert--stats :selector ... :tests ... :test-m
  ert-run-tests((not (or (tag :unstable) (tag :nativecomp))) #f(compil
  ert-run-tests-batch((not (or (tag :unstable) (tag :nativecomp))))
  ert-run-tests-batch-and-exit((not (or (tag :unstable) (tag :nativeco
  eval((ert-run-tests-batch-and-exit '(not (or (tag :unstable) (tag :n
  command-line-1(("-L" ";." "-l" "ert" "--eval" "(setq treesit-extra-l
  command-line()
  normal-top-level()
Test editfns-tests-styled-print condition:
    (ert-test-failed
     ((should (string= (format "%S" ...) str)) :form
      (string= "\"ion-a\""
	       "\"[1] ĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀ\"")
      :value nil :explanation
      (arrays-of-different-length 7 106 "\"ion-a\""
				  "\"[1] ĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀĀ\""
				  first-mismatch-at 1)))
   FAILED   4/24  editfns-tests-styled-print (0.041935 sec) at src/editfns-tests.el:537

What did I miss?