Subject: Re: bug#14120: invalid load-history in emacsen that CANNOT_DUMP

From: Stefan Monnier <[email-masked]>
Date: Mon, 17 Feb 2020 12:46:14 -0500

> 2.  Put a breakpoint on lread.c:build_load_history and watch how
> many times it is called and with wich params. It seems a very long list
> of params

It's called too often, that's not workable.
I was thinking of putting an assertion in there instead, maybe something
like the patch below.

> The function above could be modified for removing the stringp
> validation. And every time load-history-filename-element is called
> when an error happens that function show me the file on the history to
> which the spurious symbol belongs to?

The problem is that the file name is the string that's not there :-(

But maybe showing us the complete `load-history` when the error (in
load-history-filename-element) is caught might give us enough of a hint
(by looking at the entries nearby to try and infer the order of
operations at the time the broken entry was added)?

        Stefan

diff --git a/src/lread.c b/src/lread.c
index c124d5a1d8..7f5f1394c7 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1876,8 +1876,14 @@ build_load_history (Lisp_Object filename, bool entire)
      front of load-history, the most-recently-loaded position.  Also
      do this if we didn't find an existing member for the file.  */
   if (entire || !foundit)
-    Vload_history = Fcons (Fnreverse (Vcurrent_load_list),
-			   Vload_history);
+    {
+      Lisp_Object tem = Fnreverse (Vcurrent_load_list);
+      eassert (EQ (filename, Fcar (tem)));
+      Vload_history = Fcons (tem, Vload_history);
+      /* FIXME: There should be an unbind_to right after calling us which
+         should re-establish the previous value of Vcurrent_load_list.  */
+      Vcurrent_load_list = Qt;
+    }
 }
 
 static void