diff options
author | Josh Rahm <rahm@google.com> | 2024-02-21 14:07:13 -0700 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2024-02-21 14:07:13 -0700 |
commit | b5e1bf74ae26b57815a5dba24774ffac45603a66 (patch) | |
tree | 5efd56bf28cf9428620b74bfdab09faa8e97ec84 | |
parent | b68672eba4849628a58dfdddbb5ffa42e05db024 (diff) | |
download | wetterhorn-b5e1bf74ae26b57815a5dba24774ffac45603a66.tar.gz wetterhorn-b5e1bf74ae26b57815a5dba24774ffac45603a66.tar.bz2 wetterhorn-b5e1bf74ae26b57815a5dba24774ffac45603a66.zip |
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.
-rw-r--r-- | src/Wetterhorn/Core.hs | 2 | ||||
-rw-r--r-- | src/harness_adapter.c | 9 |
2 files changed, 10 insertions, 1 deletions
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 |