From b5e1bf74ae26b57815a5dba24774ffac45603a66 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Wed, 21 Feb 2024 14:07:13 -0700 Subject: Do a major garbage collection before hot reloading the plugin. This is done to cleanup the dangling reference to the opaque state before unloading the plugin. This fixes the problem where the runtime gets a "strange object" during garbage collection after hot-reloading the plugin while keeping the RTS running. --- src/Wetterhorn/Core.hs | 2 +- src/harness_adapter.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Wetterhorn/Core.hs b/src/Wetterhorn/Core.hs index 36b0f82..2f885f9 100644 --- a/src/Wetterhorn/Core.hs +++ b/src/Wetterhorn/Core.hs @@ -101,7 +101,7 @@ defaultConfig = WConfig { keybindingHandler = \keyEvent -> do i <- incrementState - wio $ printf "%d - got %s\n" i (show keyEvent) + wio $ printf "%d - Got %s\n" i (show keyEvent) maybe (return False) (fmap (const True)) $ Map.lookup (state keyEvent, modifiers keyEvent, keysym keyEvent) diff --git a/src/harness_adapter.c b/src/harness_adapter.c index b18f8d2..8663b6a 100644 --- a/src/harness_adapter.c +++ b/src/harness_adapter.c @@ -16,6 +16,8 @@ void* get_foreign_interface() return foreign_interface; } +extern void performMajorGC(); + void plugin_metaload(int argc, char** argv) { hs_init(&argc, &argv); @@ -25,7 +27,14 @@ void plugin_load(int argc, char **argv, foreign_interface_t* fintf) { hs_init(&argc, &argv); foreign_interface = fintf; } + void plugin_teardown(opqst_t st) { + // the opaque state should be dereferenced by now. Perform a major GC to help + // clean up before doing a reload. + // + // Used primarily in the case where the RTS is kept alive when performing a + // hot-reload. + performMajorGC(); hs_exit(); // There's a race condition between when this shared library is unloaded and -- cgit