From 125714a693af560707385ba03fe59bcf5e488c08 Mon Sep 17 00:00:00 2001
From: Ben Gamari <ben@smart-cactus.org>
Date: Wed, 19 Oct 2022 21:25:19 -0400
Subject: [PATCH] base: Factor out errorBelch

This was useful when debugging
---
 .../ghc-internal/src/GHC/Internal/TopHandler.hs      | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libraries/ghc-internal/src/GHC/Internal/TopHandler.hs b/libraries/ghc-internal/src/GHC/Internal/TopHandler.hs
index c04c13a3a311..f0e089eae422 100644
--- a/libraries/ghc-internal/src/GHC/Internal/TopHandler.hs
+++ b/libraries/ghc-internal/src/GHC/Internal/TopHandler.hs
@@ -216,13 +216,17 @@ real_handler exit se = do
 -- don't use errorBelch() directly, because we cannot call varargs functions
 -- using the FFI.
 foreign import ccall unsafe "HsBase.h errorBelch2"
-   errorBelch :: CString -> CString -> IO ()
+    c_errorBelch :: CString -> CString -> IO ()
+
+errorBelch :: String -> IO ()
+errorBelch msg =
+    withCAString "%s" $ \fmt ->
+      withCAString msg $ \msg' ->
+          c_errorBelch fmt msg'
 
 disasterHandler :: (Int -> IO a) -> IOError -> IO a
 disasterHandler exit _ =
-  withCAString "%s" $ \fmt ->
-    withCAString msgStr $ \msg ->
-      errorBelch fmt msg >> exit 1
+    errorBelch msgStr >> exit 1
   where
     msgStr =
         "encountered an exception while trying to report an exception.\n" ++
-- 
GitLab