]> git.eshelyaron.com Git - emacs.git/commitdiff
Add late load pdumper hooks so these can call into Lisp
authorAndrea Corallo <akrl@sdf.org>
Wed, 10 Feb 2021 20:48:19 +0000 (21:48 +0100)
committerAndrea Corallo <akrl@sdf.org>
Wed, 10 Feb 2021 21:03:34 +0000 (22:03 +0100)
* src/pdumper.h (pdumper_do_now_and_after_late_load): New function.
* src/pdumper.c (dump_late_hooks, nr_dump_late_hooks): New static
variables.
(dump_metadata_for_pdumper): Add support for late load hooks.
(pdumper_do_now_and_after_late_load_impl): New functions.
(pdumper_load): Add support for late load hooks.
* src/window.c (init_window_once): Register
'init_window_once_for_pdumper' to be executed after late load.

src/pdumper.c
src/pdumper.h
src/window.c

index f0711078a5aeb01ef81c42bf0a1e467b9499f177..1f1f6e05df4f73c3b0585d875dfca8344d9678f5 100644 (file)
@@ -121,6 +121,9 @@ static const char dump_magic[16] = {
 static pdumper_hook dump_hooks[24];
 static int nr_dump_hooks = 0;
 
+static pdumper_hook dump_late_hooks[24];
+static int nr_dump_late_hooks = 0;
+
 static struct
 {
   void *mem;
@@ -3245,6 +3248,12 @@ dump_metadata_for_pdumper (struct dump_context *ctx)
                                       (void const *) dump_hooks[i]);
   dump_emacs_reloc_immediate_int (ctx, &nr_dump_hooks, nr_dump_hooks);
 
+  for (int i = 0; i < nr_dump_late_hooks; ++i)
+    dump_emacs_reloc_to_emacs_ptr_raw (ctx, &dump_late_hooks[i],
+                                      (void const *) dump_late_hooks[i]);
+  dump_emacs_reloc_immediate_int (ctx, &nr_dump_late_hooks,
+                                 nr_dump_late_hooks);
+
   for (int i = 0; i < nr_remembered_data; ++i)
     {
       dump_emacs_reloc_to_emacs_ptr_raw (ctx, &remembered_data[i].mem,
@@ -4316,6 +4325,15 @@ pdumper_do_now_and_after_load_impl (pdumper_hook hook)
   hook ();
 }
 
+void
+pdumper_do_now_and_after_late_load_impl (pdumper_hook hook)
+{
+  if (nr_dump_late_hooks == ARRAYELTS (dump_late_hooks))
+    fatal ("out of dump hooks: make dump_late_hooks[] bigger");
+  dump_late_hooks[nr_dump_late_hooks++] = hook;
+  hook ();
+}
+
 static void
 pdumper_remember_user_data_1 (void *mem, int nbytes)
 {
@@ -5597,6 +5615,12 @@ pdumper_load (const char *dump_filename, char *argv0, char const *original_pwd)
 
   dump_do_all_dump_reloc_for_phase (header, dump_base, LATE_RELOCS);
   dump_do_all_dump_reloc_for_phase (header, dump_base, VERY_LATE_RELOCS);
+
+  /* Run the functions Emacs registered for doing post-dump-load
+     initialization.  */
+  for (int i = 0; i < nr_dump_late_hooks; ++i)
+    dump_late_hooks[i] ();
+
   initialized = true;
 
   struct timespec load_timespec =
index 24e99e22c7a48dd22dfdcf11ff3abd507dbdbf52..49e6739b0dced0a576dfb59398b3223a6b7ace24 100644 (file)
@@ -81,6 +81,7 @@ pdumper_remember_lv_ptr_raw (void *ptr, enum Lisp_Type type)
 
 typedef void (*pdumper_hook)(void);
 extern void pdumper_do_now_and_after_load_impl (pdumper_hook hook);
+extern void pdumper_do_now_and_after_late_load_impl (pdumper_hook hook);
 
 INLINE void
 pdumper_do_now_and_after_load (pdumper_hook hook)
@@ -92,6 +93,18 @@ pdumper_do_now_and_after_load (pdumper_hook hook)
 #endif
 }
 
+/* Same as 'pdumper_do_now_and_after_load' but for hooks running code
+   that can call into Lisp.  */
+INLINE void
+pdumper_do_now_and_after_late_load (pdumper_hook hook)
+{
+#ifdef HAVE_PDUMPER
+  pdumper_do_now_and_after_late_load_impl (hook);
+#else
+  hook ();
+#endif
+}
+
 /* Macros useful in pdumper callback functions.  Assign a value if
    we're loading a dump and the value needs to be reset to its
    original value, and if we're initializing for the first time,
index eb16e2a43389badbe8980d069955dc83780a927c..f8b97287e64dc6df302ca0f8912546669aa96110 100644 (file)
@@ -8134,7 +8134,7 @@ init_window_once (void)
   minibuf_selected_window = Qnil;
   staticpro (&minibuf_selected_window);
 
-  pdumper_do_now_and_after_load (init_window_once_for_pdumper);
+  pdumper_do_now_and_after_late_load (init_window_once_for_pdumper);
 }
 
 static void init_window_once_for_pdumper (void)