From dba9bbcffc6436d37dec362b03dfe84c9707add6 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 3 Jun 2022 15:57:06 +0200 Subject: Use weak symbol for rtsConfig (support existence of TH in client programs) --- cbits/hook.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'cbits/hook.c') 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; -- cgit v1.2.3-54-g00ecf