{-# LANGUAGE MagicHash #-}
module GHC.Weak.Finalize
(
setFinalizerExceptionHandler
, getFinalizerExceptionHandler
, printToHandleFinalizerExceptionHandler
, GHC.Weak.Finalize.runFinalizerBatch
) where
import GHC.Internal.Weak.Finalize
import GHC.Internal.Base (return, (++))
import GHC.Internal.Exception
import GHC.Internal.IO (catchException)
import GHC.Internal.IO.Handle.Types (Handle)
import GHC.Internal.IO.Handle.Text (hPutStrLn)
import GHC.Internal.Prim (Array#, State#, RealWorld)
import GHC.Internal.Types (Int, IO)
{-# DEPRECATED runFinalizerBatch
"This function is internal to GHC. It will not be exported in future." #-}
runFinalizerBatch :: Int
-> Array# (State# RealWorld -> State# RealWorld)
-> IO ()
runFinalizerBatch :: Int -> Array# (State# RealWorld -> State# RealWorld) -> IO ()
runFinalizerBatch = Int -> Array# (State# RealWorld -> State# RealWorld) -> IO ()
GHC.Internal.Weak.Finalize.runFinalizerBatch
printToHandleFinalizerExceptionHandler :: Handle -> SomeException -> IO ()
printToHandleFinalizerExceptionHandler :: Handle -> SomeException -> IO ()
printToHandleFinalizerExceptionHandler Handle
hdl SomeException
se =
Handle -> String -> IO ()
hPutStrLn Handle
hdl String
msg IO () -> (SomeException -> IO ()) -> IO ()
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`catchException` (\(SomeException e
_) -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ())
where
msg :: String
msg = String
"Exception during weak pointer finalization (ignored): " String -> String -> String
forall a. [a] -> [a] -> [a]
++ SomeException -> String
forall e. Exception e => e -> String
displayException SomeException
se String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n"