summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2022-06-03 15:57:06 +0200
committerTom Smeding <tom@tomsmeding.com>2022-06-03 15:57:06 +0200
commitdba9bbcffc6436d37dec362b03dfe84c9707add6 (patch)
treee9dfe4195c64e19129e1d9cf77a6e683a9a377fc
parentdf15ed04bd85105178e236b6ca8caa5c78f4e523 (diff)
Use weak symbol for rtsConfig (support existence of TH in client programs)
-rw-r--r--cbits/hook.c7
-rw-r--r--test/Main.hs2
2 files changed, 8 insertions, 1 deletions
diff --git a/cbits/hook.c b/cbits/hook.c
index b13576f..22aa259 100644
--- a/cbits/hook.c
+++ b/cbits/hook.c
@@ -9,7 +9,7 @@ static size_t min_sz(size_t a, size_t b) {
return a < b ? a : b;
}
-extern RtsConfig rtsConfig;
+extern RtsConfig __attribute__((weak)) rtsConfig;
// A copy of GCDetails_ with known structure that can be depended on by the Haskell code.
struct ShadowDetails {
@@ -226,6 +226,11 @@ bool set_gchook(void) {
goto unlock_return_retval;
}
+ if (&rtsConfig == NULL) {
+ fprintf(stderr, "ghc-gc-hook: ERROR: rtsConfig not defined; the GC hook cannot be used from within a TemplateHaskell splice\n");
+ goto unlock_return_retval;
+ }
+
old_hook = rtsConfig.gcDoneHook;
rtsConfig.gcDoneHook = hook_callback;
diff --git a/test/Main.hs b/test/Main.hs
index aad5ebb..90e5f90 100644
--- a/test/Main.hs
+++ b/test/Main.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE TemplateHaskell #-}
module Main where
import Control.Monad (forM_, when)
@@ -10,6 +11,7 @@ import GHC.GC_Hook
foreign import ccall "get_my_delegate_ptr" c_get_my_delegate_ptr :: IO (Ptr ())
+$(return [])
{-# NOINLINE invokeGCsometimes #-}
invokeGCsometimes :: IO ()