Subject: bug#78917: feature/igc [PATCH] Avoid chaining finalizers together

From: Pip Cet <[email-masked]>
Date: Sat, 28 Jun 2025 09:14:12 +0000

"Helmut Eller" <[email-masked]> writes:

> Lisp_Finalizers are currently chained together in a doubly linked list.
> This prevents them from being collected.  I propose that we simply don't
> use this list with MPS.
>
> The first patch is minimalistic: it only skips finalizer_insert when
> creating finalizers.
>
> The second patch is more thorough: it #ifdefs away the prev/next fields
> entirely.

Looks good, except for the addition of igc--process-messages;
igc--collect should process *all* messages before returning, and
exposing a function that processes only some of the messages doesn't
seem useful to me.

The test probably should be rewritten to something like this:

;; Ensure finalizers are collected and bug#78917 doesn't reappear.
(ert-deftest test-two-finalizers ()
  ;; this test will usually succeed, but might fail due to unpredictable
  ;; references to the finalizer on the C stack or elsewhere.
  :tags '(:igc :unstable)
  (let* ((garbage-collection-messages t)
         (finalizer-1-called nil)
         (finalizer-2-called nil)
         (finalizer-1 (make-finalizer (lambda (setq finalizer-1-called t))))
         (finalizer-2 (make-finalizer (lambda (setq finalizer-2-called t)))))
    (dotimes (_ 3)
      (igc--collect)
      (sleep-for 0.1))
    (should (not finalizer-1-called))
    (should (not finalizer-2-called))
    (setq finalizer-1 nil)
    (dotimes (_ 1)
      (igc--collect)
      (accept-process-output nil 1 0 t))
    (should finalizer-1-called)
    (should (not finalizer-2-called))))

Pip