Subject: Re: bug#66743: 30.0.50; Crash when dumping reftex

From: Ihor Radchenko <[email-masked]>
Date: Thu, 26 Oct 2023 09:38:40 +0000

Gerd Möllmann <[email-masked]> writes:

>>> Emacs is always dumped with a few buffers, because temacs needs them
>>> to do the dumping.  See this comment text from buffer.c:
>>>
>>> 	 Implementation notes: the buffers we carry from temacs are:
>>> 	 " prin1", "*scratch*", " *Minibuf-0*", "*Messages*", and
>>> 	 " *code-conversion-work*".  They are created by
>>> 	 init_buffer_once and init_window_once (which are not called
>>> 	 in the dumped Emacs), and by the first call to coding.c
>>> 	 routines.
>>
>> Thanks.
>>
>> So, one idea would be to try and move the creation of these buffers from
>> the init_*_once functions to the "normal" init functions, and see what
>> happens. One would also have to take a closer look at coding.c, of course.
>
> Actually, this is bug#59029, sort of.
>
> TLDR is that the code to dump itrees is there, somewhere in git, but has
> an infinite recursion bug. So, I guess it should first be tried to
> revive that code and fix it (tests should also exist, IIUC).

While I agree that dumping buffer overlays would be nice to have, I
think I found a simple workaround for the specific issue I reported.
We may simply make sure that the overlays do not belong to any buffer -
it is good enough for the purposes of reftex library, where the overlay
objects are created once and then modified by side effect for actual
use.

See the attached patch.

>From 3bc99957796a8e8f92c8cb57d7102ee0461b3d86 Mon Sep 17 00:00:00 2001
Message-ID: <[email-masked]>
From: Ihor Radchenko <[email-masked]>
Date: Thu, 26 Oct 2023 12:34:58 +0300
Subject: [PATCH] * lisp/textmodes/reftex.el: Work around pdumper crash
 (bug#66743)

(reftex-highlight-overlays): Make sure that the overlays objects are
not assigned to any buffer.  This is to work around pdumping not
supporting dumping buffer overlays (yet).
---
 lisp/textmodes/reftex.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el
index 0a1fa8580d0..5f564b7f9eb 100644
--- a/lisp/textmodes/reftex.el
+++ b/lisp/textmodes/reftex.el
@@ -2075,13 +2075,15 @@ 'reftex-delete-overlay
 (defvar reftex-highlight-overlays [nil nil nil])
 
 ;; Initialize the overlays
-(aset reftex-highlight-overlays 0 (make-overlay 1 1))
+;; Ensure that the overlays are not assigned to any buffer to avoid
+;; crashing pdumper, if it is used to dump this library.  See bug#66743.
+(aset reftex-highlight-overlays 0 (with-temp-buffer (make-overlay 1 1)))
 (overlay-put (aref reftex-highlight-overlays 0)
              'face 'highlight)
-(aset reftex-highlight-overlays 1 (make-overlay 1 1))
+(aset reftex-highlight-overlays 1 (with-temp-buffer (make-overlay 1 1)))
 (overlay-put (aref reftex-highlight-overlays 1)
              'face reftex-cursor-selected-face)
-(aset reftex-highlight-overlays 2 (make-overlay 1 1))
+(aset reftex-highlight-overlays 2 (with-temp-buffer (make-overlay 1 1)))
 (overlay-put (aref reftex-highlight-overlays 2)
              'face reftex-cursor-selected-face)
 
-- 
2.42.0

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>