From 5aedd01fd07e5401143c090b8a53ab69fd4ea816 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 18 Nov 2022 15:47:19 +1300 Subject: [PATCH] Add error detection to FcRange bindings. --- Graphics/Text/Font/Choose/Range.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Graphics/Text/Font/Choose/Range.hs b/Graphics/Text/Font/Choose/Range.hs index 808c917..5c5e647 100644 --- a/Graphics/Text/Font/Choose/Range.hs +++ b/Graphics/Text/Font/Choose/Range.hs @@ -8,6 +8,7 @@ import Foreign.Storable (peek) import GHC.Generics (Generic) import Data.Hashable (Hashable) +import Graphics.Text.Font.Choose.Result (throwNull, throwFalse) data Range = Range Double Double deriving (Eq, Show, Ord, Generic) iRange i j = toEnum i `Range` toEnum j @@ -21,14 +22,14 @@ data Range' type Range_ = Ptr Range' withRange :: Range -> (Range_ -> IO a) -> IO a -withRange (Range i j) = bracket (fcRangeCreateDouble i j) fcRangeDestroy +withRange (Range i j) = bracket (throwNull <$> fcRangeCreateDouble i j) fcRangeDestroy foreign import ccall "FcRangeCreateDouble" fcRangeCreateDouble :: Double -> Double -> IO Range_ foreign import ccall "FcRangeDestroy" fcRangeDestroy :: Range_ -> IO () thawRange :: Range_ -> IO Range thawRange range' = alloca $ \i' -> alloca $ \j' -> do - fcRangeGetDouble range' i' j' + throwFalse <$> fcRangeGetDouble range' i' j' i <- peek i' j <- peek j' return $ Range i j -- 2.30.2