{-# LANGUAGE DeriveDataTypeable, EmptyDataDecls, ForeignFunctionInterface #-}
module Data.Text.ICU.Spoof.Internal
(
MSpoof(..)
, Spoof(..)
, USpoof
, withSpoof
, wrap
, wrapWithSerialized
) where
import Data.Typeable (Typeable)
import Data.Word (Word8)
import Foreign.ForeignPtr (ForeignPtr, newForeignPtr, withForeignPtr)
import Foreign.Ptr (FunPtr, Ptr)
data USpoof
data MSpoof = MSpoof {
MSpoof -> Maybe (ForeignPtr Word8)
serializedBuf :: Maybe (ForeignPtr Word8)
, MSpoof -> ForeignPtr USpoof
spoofPtr :: {-# UNPACK #-} !(ForeignPtr USpoof)
} deriving (Typeable)
newtype Spoof = S MSpoof
deriving (Typeable)
withSpoof :: MSpoof -> (Ptr USpoof -> IO a) -> IO a
withSpoof :: MSpoof -> (Ptr USpoof -> IO a) -> IO a
withSpoof (MSpoof Maybe (ForeignPtr Word8)
_ ForeignPtr USpoof
spoof) = ForeignPtr USpoof -> (Ptr USpoof -> IO a) -> IO a
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr USpoof
spoof
{-# INLINE withSpoof #-}
wrap :: Ptr USpoof -> IO MSpoof
wrap :: Ptr USpoof -> IO MSpoof
wrap = (ForeignPtr USpoof -> MSpoof)
-> IO (ForeignPtr USpoof) -> IO MSpoof
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe (ForeignPtr Word8) -> ForeignPtr USpoof -> MSpoof
MSpoof Maybe (ForeignPtr Word8)
forall a. Maybe a
Nothing) (IO (ForeignPtr USpoof) -> IO MSpoof)
-> (Ptr USpoof -> IO (ForeignPtr USpoof))
-> Ptr USpoof
-> IO MSpoof
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FinalizerPtr USpoof -> Ptr USpoof -> IO (ForeignPtr USpoof)
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr USpoof
uspoof_close
{-# INLINE wrap #-}
wrapWithSerialized :: ForeignPtr Word8 -> Ptr USpoof -> IO MSpoof
wrapWithSerialized :: ForeignPtr Word8 -> Ptr USpoof -> IO MSpoof
wrapWithSerialized ForeignPtr Word8
s = (ForeignPtr USpoof -> MSpoof)
-> IO (ForeignPtr USpoof) -> IO MSpoof
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe (ForeignPtr Word8) -> ForeignPtr USpoof -> MSpoof
MSpoof (Maybe (ForeignPtr Word8) -> ForeignPtr USpoof -> MSpoof)
-> Maybe (ForeignPtr Word8) -> ForeignPtr USpoof -> MSpoof
forall a b. (a -> b) -> a -> b
$ ForeignPtr Word8 -> Maybe (ForeignPtr Word8)
forall a. a -> Maybe a
Just ForeignPtr Word8
s) (IO (ForeignPtr USpoof) -> IO MSpoof)
-> (Ptr USpoof -> IO (ForeignPtr USpoof))
-> Ptr USpoof
-> IO MSpoof
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FinalizerPtr USpoof -> Ptr USpoof -> IO (ForeignPtr USpoof)
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr USpoof
uspoof_close
{-# INLINE wrapWithSerialized #-}
foreign import ccall unsafe "hs_text_icu.h &__hs_uspoof_close" uspoof_close
:: FunPtr (Ptr USpoof -> IO ())