~alcinnz/harfbuzz-pure

ref: 2546e12708a4def41cfbb36f35666ca2d702b8c7 harfbuzz-pure/Data/Text/Glyphize/Oom.hs -rw-r--r-- 429 bytes
2546e127 — Adrian Cochrane Implement more typeclasses & ensure empty input don't throw errors. 1 year, 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module Data.Text.Glyphize.Oom where

import Control.Exception
import Foreign.Ptr (nullPtr, Ptr)

data HarfbuzzError = OutOfMemory deriving (Show)
instance Exception HarfbuzzError

throwFalse :: IO Bool -> IO ()
throwFalse cb = do
    ret <- cb
    if ret then return () else throwIO OutOfMemory

throwNull :: IO (Ptr a) -> IO (Ptr a)
throwNull cb = do
    ptr <- cb
    if ptr == nullPtr then throwIO OutOfMemory else return ptr