From 9942f874b2b421d7602c9501a628fec66bf78757 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 18 Nov 2022 12:39:39 +1300 Subject: [PATCH] Throw OOM errors for objectsets. --- Graphics/Text/Font/Choose/ObjectSet.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Graphics/Text/Font/Choose/ObjectSet.hs b/Graphics/Text/Font/Choose/ObjectSet.hs index ef93a5b..e2a0e32 100644 --- a/Graphics/Text/Font/Choose/ObjectSet.hs +++ b/Graphics/Text/Font/Choose/ObjectSet.hs @@ -5,6 +5,7 @@ import Foreign.C.String (CString, withCString) import Control.Monad (forM) import Control.Exception (bracket) +import Graphics.Text.Font.Choose.Result (throwFalse, throwNull) type ObjectSet = [String] @@ -16,12 +17,13 @@ type ObjectSet_ = Ptr ObjectSet' withObjectSet :: ObjectSet -> (ObjectSet_ -> IO a) -> IO a withObjectSet objs cb = withNewObjectSet $ \objs' -> do - forM objs $ \obj -> withCString obj $ fcObjectSetAdd objs' + forM objs $ \obj -> withCString obj $ \obj' -> + throwFalse <$> fcObjectSetAdd objs' obj' cb objs' foreign import ccall "FcObjectSetAdd" fcObjectSetAdd :: ObjectSet_ -> CString -> IO Bool withNewObjectSet :: (ObjectSet_ -> IO a) -> IO a -withNewObjectSet cb = bracket fcObjectSetCreate fcObjectSetDestroy cb +withNewObjectSet = bracket (throwNull <$> fcObjectSetCreate) fcObjectSetDestroy foreign import ccall "FcObjectSetCreate" fcObjectSetCreate :: IO ObjectSet_ foreign import ccall "FcObjectSetDestroy" fcObjectSetDestroy :: ObjectSet_ -> IO () -- 2.30.2