diff options
-rw-r--r-- | cbits/hook.c | 7 | ||||
-rw-r--r-- | test/Main.hs | 2 |
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 () |