{-# LINE 1 "src/Data/PhoneNumber/Internal/Common.chs" #-}
module Data.PhoneNumber.Internal.Common where
import qualified Foreign.C.Types as C2HSImp
import Control.Arrow
import Data.ByteString (ByteString)
import Data.ByteString.Unsafe
import Foreign
import Foreign.C.Types
alloca2 :: (Storable a, Storable b) => ((Ptr a, Ptr b) -> IO c) -> IO c
alloca2 :: forall a b c.
(Storable a, Storable b) =>
((Ptr a, Ptr b) -> IO c) -> IO c
alloca2 (Ptr a, Ptr b) -> IO c
k = (Ptr a -> IO c) -> IO c
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr a -> IO c) -> IO c) -> (Ptr a -> IO c) -> IO c
forall a b. (a -> b) -> a -> b
$ \Ptr a
p1 -> (Ptr b -> IO c) -> IO c
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr b -> IO c) -> IO c) -> (Ptr b -> IO c) -> IO c
forall a b. (a -> b) -> a -> b
$ \Ptr b
p2 -> (Ptr a, Ptr b) -> IO c
k (Ptr a
p1, Ptr b
p2)
withByteString :: ByteString -> ((Ptr CChar, (C2HSImp.CULong)) -> IO a) -> IO a
withByteString :: forall a. ByteString -> ((Ptr CChar, CULong) -> IO a) -> IO a
withByteString ByteString
bs (Ptr CChar, CULong) -> IO a
k = ByteString -> (CStringLen -> IO a) -> IO a
forall a. ByteString -> (CStringLen -> IO a) -> IO a
unsafeUseAsCStringLen ByteString
bs ((CStringLen -> IO a) -> IO a) -> (CStringLen -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ (Ptr CChar, CULong) -> IO a
k ((Ptr CChar, CULong) -> IO a)
-> (CStringLen -> (Ptr CChar, CULong)) -> CStringLen -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> CULong) -> CStringLen -> (Ptr CChar, CULong)
forall b c d. (b -> c) -> (d, b) -> (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second Int -> CULong
forall a b. (Integral a, Num b) => a -> b
fromIntegral
acquireCString :: Ptr CChar -> (C2HSImp.CULong) -> IO ByteString
acquireCString :: Ptr CChar -> CULong -> IO ByteString
acquireCString = ((Ptr CChar, CULong) -> IO ByteString)
-> Ptr CChar -> CULong -> IO ByteString
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((Ptr CChar, CULong) -> IO ByteString)
-> Ptr CChar -> CULong -> IO ByteString)
-> ((Ptr CChar, CULong) -> IO ByteString)
-> Ptr CChar
-> CULong
-> IO ByteString
forall a b. (a -> b) -> a -> b
$ CStringLen -> IO ByteString
unsafePackMallocCStringLen (CStringLen -> IO ByteString)
-> ((Ptr CChar, CULong) -> CStringLen)
-> (Ptr CChar, CULong)
-> IO ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CULong -> Int) -> (Ptr CChar, CULong) -> CStringLen
forall b c d. (b -> c) -> (d, b) -> (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second CULong -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral