{-# LANGUAGE CPP #-}
module UnliftIO.Foreign (
module Data.Bits
, module Data.Int
, module Data.Word
, module Foreign.C.Types
, CString
, CStringLen
, peekCString
, peekCStringLen
, newCString
, newCStringLen
, withCString
, withCStringLen
, charIsRepresentable
, castCharToCChar
, castCCharToChar
, castCharToCUChar
, castCUCharToChar
, castCharToCSChar
, castCSCharToChar
, peekCAString
, peekCAStringLen
, newCAString
, newCAStringLen
, withCAString
, withCAStringLen
, CWString
, CWStringLen
, peekCWString
, peekCWStringLen
, newCWString
, newCWStringLen
, withCWString
, withCWStringLen
, Errno(..)
, eOK
, e2BIG
, eACCES
, eADDRINUSE
, eADDRNOTAVAIL
, eADV
, eAFNOSUPPORT
, eAGAIN
, eALREADY
, eBADF
, eBADMSG
, eBADRPC
, eBUSY
, eCHILD
, eCOMM
, eCONNABORTED
, eCONNREFUSED
, eCONNRESET
, eDEADLK
, eDESTADDRREQ
, eDIRTY
, eDOM
, eDQUOT
, eEXIST
, eFAULT
, eFBIG
, eFTYPE
, eHOSTDOWN
, eHOSTUNREACH
, eIDRM
, eILSEQ
, eINPROGRESS
, eINTR
, eINVAL
, eIO
, eISCONN
, eISDIR
, eLOOP
, eMFILE
, eMLINK
, eMSGSIZE
, eMULTIHOP
, eNAMETOOLONG
, eNETDOWN
, eNETRESET
, eNETUNREACH
, eNFILE
, eNOBUFS
, eNODATA
, eNODEV
, eNOENT
, eNOEXEC
, eNOLCK
, eNOLINK
, eNOMEM
, eNOMSG
, eNONET
, eNOPROTOOPT
, eNOSPC
, eNOSR
, eNOSTR
, eNOSYS
, eNOTBLK
, eNOTCONN
, eNOTDIR
, eNOTEMPTY
, eNOTSOCK
, eNOTSUP
, eNOTTY
, eNXIO
, eOPNOTSUPP
, ePERM
, ePFNOSUPPORT
, ePIPE
, ePROCLIM
, ePROCUNAVAIL
, ePROGMISMATCH
, ePROGUNAVAIL
, ePROTO
, ePROTONOSUPPORT
, ePROTOTYPE
, eRANGE
, eREMCHG
, eREMOTE
, eROFS
, eRPCMISMATCH
, eRREMOTE
, eSHUTDOWN
, eSOCKTNOSUPPORT
, eSPIPE
, eSRCH
, eSRMNT
, eSTALE
, eTIME
, eTIMEDOUT
, eTOOMANYREFS
, eTXTBSY
, eUSERS
, eWOULDBLOCK
, eXDEV
, isValidErrno
, getErrno
, resetErrno
, errnoToIOError
, throwErrno
, throwErrnoIf
, throwErrnoIf_
, throwErrnoIfRetry
, throwErrnoIfRetry_
, throwErrnoIfMinus1
, throwErrnoIfMinus1_
, throwErrnoIfMinus1Retry
, throwErrnoIfMinus1Retry_
, throwErrnoIfNull
, throwErrnoIfNullRetry
, throwErrnoIfRetryMayBlock
, throwErrnoIfRetryMayBlock_
, throwErrnoIfMinus1RetryMayBlock
, throwErrnoIfMinus1RetryMayBlock_
, throwErrnoIfNullRetryMayBlock
, throwErrnoPath
, throwErrnoPathIf
, throwErrnoPathIf_
, throwErrnoPathIfNull
, throwErrnoPathIfMinus1
, throwErrnoPathIfMinus1_
, Ptr
, nullPtr
, castPtr
, plusPtr
, alignPtr
, minusPtr
, FunPtr
, nullFunPtr
, castFunPtr
, castFunPtrToPtr
, castPtrToFunPtr
, freeHaskellFunPtr
, IntPtr(..)
, ptrToIntPtr
, intPtrToPtr
, WordPtr(..)
, ptrToWordPtr
, wordPtrToPtr
, ForeignPtr
, FinalizerPtr
, FinalizerEnvPtr
, newForeignPtr
, newForeignPtr_
, addForeignPtrFinalizer
, newForeignPtrEnv
, addForeignPtrFinalizerEnv
, withForeignPtr
, finalizeForeignPtr
, touchForeignPtr
, castForeignPtr
#if MIN_VERSION_base(4,10,0)
, plusForeignPtr
#endif
, mallocForeignPtr
, mallocForeignPtrBytes
, mallocForeignPtrArray
, mallocForeignPtrArray0
, newGHCForeignPtr
, addGHCForeignPtrFinalizer
, unsafeForeignPtrToPtr
, StablePtr
, newStablePtr
, deRefStablePtr
, freeStablePtr
, castStablePtrToPtr
, castPtrToStablePtr
, Storable(..)
, alloca
, allocaBytes
, allocaBytesAligned
, malloc
, mallocBytes
#if MIN_VERSION_base(4,8,0)
, calloc
, callocBytes
#endif
, realloc
, reallocBytes
, free
, finalizerFree
, mallocArray
, mallocArray0
, allocaArray
, allocaArray0
, reallocArray
, reallocArray0
#if MIN_VERSION_base(4,8,0)
, callocArray
, callocArray0
#endif
, peekArray
, peekArray0
, pokeArray
, pokeArray0
, newArray
, newArray0
, withArray
, withArray0
, withArrayLen
, withArrayLen0
, copyArray
, moveArray
, lengthArray0
, advancePtr
, throwIf
, throwIf_
, throwIfNeg
, throwIfNeg_
, throwIfNull
, Pool
, newPool
, freePool
, withPool
, pooledMalloc
, pooledMallocBytes
, pooledRealloc
, pooledReallocBytes
, pooledMallocArray
, pooledMallocArray0
, pooledReallocArray
, pooledReallocArray0
, pooledNew
, pooledNewArray
, pooledNewArray0
, with
, new
, fromBool
, toBool
, maybeNew
, maybeWith
, maybePeek
, withMany
, copyBytes
, moveBytes
#if MIN_VERSION_base(4,8,0)
, fillBytes
#endif
) where
import Control.Monad.IO.Unlift
import Data.Bits
import Data.Int
import Data.Word
import qualified Foreign as F
import Foreign
( FinalizerEnvPtr
, FinalizerPtr
, ForeignPtr
, FunPtr
, IntPtr(..)
, Pool
, Ptr
, StablePtr
, Storable(..)
, WordPtr(..)
, advancePtr
, alignPtr
, castForeignPtr
, castFunPtr
, castFunPtrToPtr
, castPtr
, castPtrToFunPtr
, castPtrToStablePtr
, castStablePtrToPtr
, finalizerFree
, fromBool
, intPtrToPtr
, minusPtr
, nullFunPtr
, nullPtr
#if MIN_VERSION_base(4,10,0)
, plusForeignPtr
#endif
, plusPtr
, ptrToIntPtr
, ptrToWordPtr
, toBool
, withMany
, wordPtrToPtr
)
import qualified Foreign.C as F
import Foreign.C
( CString
, CStringLen
, CWString
, CWStringLen
, Errno(..)
, castCCharToChar
, castCSCharToChar
, castCUCharToChar
, castCharToCChar
, castCharToCSChar
, castCharToCSChar
, castCharToCUChar
, charIsRepresentable
, e2BIG
, eACCES
, eADDRINUSE
, eADDRNOTAVAIL
, eADV
, eAFNOSUPPORT
, eAGAIN
, eALREADY
, eBADF
, eBADMSG
, eBADRPC
, eBUSY
, eCHILD
, eCOMM
, eCONNABORTED
, eCONNREFUSED
, eCONNRESET
, eDEADLK
, eDESTADDRREQ
, eDIRTY
, eDOM
, eDQUOT
, eEXIST
, eFAULT
, eFBIG
, eFTYPE
, eHOSTDOWN
, eHOSTUNREACH
, eIDRM
, eILSEQ
, eINPROGRESS
, eINTR
, eINVAL
, eIO
, eISCONN
, eISDIR
, eLOOP
, eMFILE
, eMLINK
, eMSGSIZE
, eMULTIHOP
, eNAMETOOLONG
, eNETDOWN
, eNETRESET
, eNETUNREACH
, eNFILE
, eNOBUFS
, eNODATA
, eNODEV
, eNOENT
, eNOEXEC
, eNOLCK
, eNOLINK
, eNOMEM
, eNOMSG
, eNONET
, eNOPROTOOPT
, eNOSPC
, eNOSR
, eNOSTR
, eNOSYS
, eNOTBLK
, eNOTCONN
, eNOTDIR
, eNOTEMPTY
, eNOTSOCK
, eNOTSUP
, eNOTTY
, eNXIO
, eOK
, eOPNOTSUPP
, ePERM
, ePFNOSUPPORT
, ePIPE
, ePROCLIM
, ePROCUNAVAIL
, ePROGMISMATCH
, ePROGUNAVAIL
, ePROTO
, ePROTONOSUPPORT
, ePROTOTYPE
, eRANGE
, eREMCHG
, eREMOTE
, eROFS
, eRPCMISMATCH
, eRREMOTE
, eSHUTDOWN
, eSOCKTNOSUPPORT
, eSPIPE
, eSRCH
, eSRMNT
, eSTALE
, eTIME
, eTIMEDOUT
, eTOOMANYREFS
, eTXTBSY
, eUSERS
, eWOULDBLOCK
, eXDEV
, errnoToIOError
, isValidErrno
)
import Foreign.C.Types
import qualified Foreign.Concurrent as FC
import Foreign.ForeignPtr.Unsafe
{-# INLINE peekCString #-}
peekCString :: MonadIO m => CString -> m String
peekCString = liftIO . F.peekCString
{-# INLINE peekCStringLen #-}
peekCStringLen :: MonadIO m => CStringLen -> m String
peekCStringLen = liftIO . F.peekCStringLen
{-# INLINE newCString #-}
newCString :: MonadIO m => String -> m CString
newCString = liftIO . F.newCString
{-# INLINE newCStringLen #-}
newCStringLen :: MonadIO m => String -> m CStringLen
newCStringLen = liftIO . F.newCStringLen
{-# INLINE withCString #-}
withCString :: MonadUnliftIO m => String -> (CString -> m a) -> m a
withCString s f = withRunInIO (\u -> F.withCString s (u . f))
{-# INLINE withCStringLen #-}
withCStringLen :: MonadUnliftIO m => String -> (CStringLen -> m a) -> m a
withCStringLen s f = withRunInIO (\u -> F.withCStringLen s (u . f))
{-# INLINE peekCAString #-}
peekCAString :: MonadIO m => CString -> m String
peekCAString = liftIO . F.peekCAString
{-# INLINE peekCAStringLen #-}
peekCAStringLen :: MonadIO m => CStringLen -> m String
peekCAStringLen = liftIO . F.peekCAStringLen
{-# INLINE newCAString #-}
newCAString :: MonadIO m => String -> m CString
newCAString = liftIO . F.newCAString
{-# INLINE newCAStringLen #-}
newCAStringLen :: MonadIO m => String -> m CStringLen
newCAStringLen = liftIO . F.newCAStringLen
{-# INLINE withCAString #-}
withCAString :: MonadUnliftIO m => String -> (CString -> m a) -> m a
withCAString str f = withRunInIO (\u -> F.withCAString str (u . f))
{-# INLINE withCAStringLen #-}
withCAStringLen :: MonadUnliftIO m => String -> (CStringLen -> m a) -> m a
withCAStringLen str f = withRunInIO (\u -> F.withCAStringLen str (u . f))
{-# INLINE peekCWString #-}
peekCWString :: MonadIO m => CWString -> m String
peekCWString = liftIO . F.peekCWString
{-# INLINE peekCWStringLen #-}
peekCWStringLen :: MonadIO m => CWStringLen -> m String
peekCWStringLen = liftIO . F.peekCWStringLen
{-# INLINE newCWString #-}
newCWString :: MonadIO m => String -> m CWString
newCWString = liftIO . F.newCWString
{-# INLINE newCWStringLen #-}
newCWStringLen :: MonadIO m => String -> m CWStringLen
newCWStringLen = liftIO . F.newCWStringLen
{-# INLINE withCWString #-}
withCWString :: MonadUnliftIO m => String -> (CWString -> m a) -> m a
withCWString str f = withRunInIO (\u -> F.withCWString str (u . f))
{-# INLINE withCWStringLen #-}
withCWStringLen :: MonadUnliftIO m => String -> (CWStringLen -> m a) -> m a
withCWStringLen str f = withRunInIO (\u -> F.withCWStringLen str (u . f))
{-# INLINE getErrno #-}
getErrno :: MonadIO m => m Errno
getErrno = liftIO F.getErrno
{-# INLINE resetErrno #-}
resetErrno :: MonadIO m => m ()
resetErrno = liftIO F.resetErrno
{-# INLINE throwErrno #-}
throwErrno :: MonadIO m => String -> m a
throwErrno = liftIO . F.throwErrno
{-# INLINE throwErrnoIf #-}
throwErrnoIf :: MonadUnliftIO m => (a -> Bool) -> String -> m a -> m a
throwErrnoIf pred_ loc f = withRunInIO (\u -> F.throwErrnoIf pred_ loc (u f))
{-# INLINE throwErrnoIf_ #-}
throwErrnoIf_ :: MonadUnliftIO m => (a -> Bool) -> String -> m a -> m ()
throwErrnoIf_ pred_ loc f = withRunInIO (\u -> F.throwErrnoIf_ pred_ loc (u f))
{-# INLINE throwErrnoIfRetry #-}
throwErrnoIfRetry :: MonadUnliftIO m => (a -> Bool) -> String -> m a -> m a
throwErrnoIfRetry pred_ loc f =
withRunInIO (\u -> F.throwErrnoIfRetry pred_ loc (u f))
{-# INLINE throwErrnoIfRetry_ #-}
throwErrnoIfRetry_ :: MonadUnliftIO m => (a -> Bool) -> String -> m a -> m ()
throwErrnoIfRetry_ pred_ loc f =
withRunInIO (\u -> F.throwErrnoIfRetry_ pred_ loc (u f))
{-# INLINE throwErrnoIfMinus1 #-}
throwErrnoIfMinus1 :: (MonadUnliftIO m, Eq a, Num a) => String -> m a -> m a
throwErrnoIfMinus1 loc f = withRunInIO (\u -> F.throwErrnoIfMinus1 loc (u f))
{-# INLINE throwErrnoIfMinus1_ #-}
throwErrnoIfMinus1_ :: (MonadUnliftIO m, Eq a, Num a) => String -> m a -> m ()
throwErrnoIfMinus1_ loc f = withRunInIO (\u -> F.throwErrnoIfMinus1_ loc (u f))
{-# INLINE throwErrnoIfMinus1Retry #-}
throwErrnoIfMinus1Retry ::
(MonadUnliftIO m, Eq a, Num a) => String -> m a -> m a
throwErrnoIfMinus1Retry loc f =
withRunInIO (\u -> F.throwErrnoIfMinus1Retry loc (u f))
{-# INLINE throwErrnoIfMinus1Retry_ #-}
throwErrnoIfMinus1Retry_ ::
(MonadUnliftIO m, Eq a, Num a) => String -> m a -> m ()
throwErrnoIfMinus1Retry_ loc f =
withRunInIO (\u -> F.throwErrnoIfMinus1Retry_ loc (u f))
{-# INLINE throwErrnoIfNull #-}
throwErrnoIfNull :: MonadUnliftIO m => String -> m (Ptr a) -> m (Ptr a)
throwErrnoIfNull loc f = withRunInIO (\u -> F.throwErrnoIfNull loc (u f))
{-# INLINE throwErrnoIfNullRetry #-}
throwErrnoIfNullRetry :: MonadUnliftIO m => String -> m (Ptr a) -> m (Ptr a)
throwErrnoIfNullRetry loc f =
withRunInIO (\u -> F.throwErrnoIfNullRetry loc (u f))
{-# INLINE throwErrnoIfRetryMayBlock #-}
throwErrnoIfRetryMayBlock ::
MonadUnliftIO m => (a -> Bool) -> String -> m a -> m b -> m a
throwErrnoIfRetryMayBlock pred_ loc f on_block =
withRunInIO (\u -> F.throwErrnoIfRetryMayBlock pred_ loc (u f) (u on_block))
{-# INLINE throwErrnoIfRetryMayBlock_ #-}
throwErrnoIfRetryMayBlock_ ::
MonadUnliftIO m => (a -> Bool) -> String -> m a -> m b -> m ()
throwErrnoIfRetryMayBlock_ pred_ loc f on_block =
withRunInIO (\u -> F.throwErrnoIfRetryMayBlock_ pred_ loc (u f) (u on_block))
{-# INLINE throwErrnoIfMinus1RetryMayBlock #-}
throwErrnoIfMinus1RetryMayBlock ::
(MonadUnliftIO m, Eq a, Num a) => String -> m a -> m b -> m a
throwErrnoIfMinus1RetryMayBlock loc f on_block =
withRunInIO (\u -> F.throwErrnoIfMinus1RetryMayBlock loc (u f) (u on_block))
{-# INLINE throwErrnoIfMinus1RetryMayBlock_ #-}
throwErrnoIfMinus1RetryMayBlock_ ::
(MonadUnliftIO m, Eq a, Num a) => String -> m a -> m b -> m ()
throwErrnoIfMinus1RetryMayBlock_ loc f on_block =
withRunInIO (\u -> F.throwErrnoIfMinus1RetryMayBlock_ loc (u f) (u on_block))
{-# INLINE throwErrnoIfNullRetryMayBlock #-}
throwErrnoIfNullRetryMayBlock ::
MonadUnliftIO m => String -> m (Ptr a) -> m b -> m (Ptr a)
throwErrnoIfNullRetryMayBlock loc f on_block =
withRunInIO (\u -> F.throwErrnoIfNullRetryMayBlock loc (u f) (u on_block))
{-# INLINE throwErrnoPath #-}
throwErrnoPath :: MonadIO m => String -> FilePath -> m a
throwErrnoPath loc path = liftIO (F.throwErrnoPath loc path)
{-# INLINE throwErrnoPathIf #-}
throwErrnoPathIf ::
MonadUnliftIO m => (a -> Bool) -> String -> FilePath -> m a -> m a
throwErrnoPathIf pred_ loc path f =
withRunInIO (\u -> F.throwErrnoPathIf pred_ loc path (u f))
{-# INLINE throwErrnoPathIf_ #-}
throwErrnoPathIf_ ::
MonadUnliftIO m => (a -> Bool) -> String -> FilePath -> m a -> m ()
throwErrnoPathIf_ pred_ loc path f =
withRunInIO (\u -> F.throwErrnoPathIf_ pred_ loc path (u f))
{-# INLINE throwErrnoPathIfNull #-}
throwErrnoPathIfNull ::
MonadUnliftIO m => String -> FilePath -> m (Ptr a) -> m (Ptr a)
throwErrnoPathIfNull loc path f =
withRunInIO (\u -> F.throwErrnoPathIfNull loc path (u f))
{-# INLINE throwErrnoPathIfMinus1 #-}
throwErrnoPathIfMinus1 ::
(MonadUnliftIO m, Eq a, Num a) => String -> FilePath -> m a -> m a
throwErrnoPathIfMinus1 loc path f =
withRunInIO (\u -> F.throwErrnoPathIfMinus1 loc path (u f))
{-# INLINE throwErrnoPathIfMinus1_ #-}
throwErrnoPathIfMinus1_ ::
(MonadUnliftIO m, Eq a, Num a) => String -> FilePath -> m a -> m ()
throwErrnoPathIfMinus1_ loc path f =
withRunInIO (\u -> F.throwErrnoPathIfMinus1_ loc path (u f))
{-# INLINE freeHaskellFunPtr #-}
freeHaskellFunPtr :: MonadIO m => FunPtr a -> m ()
freeHaskellFunPtr = liftIO . F.freeHaskellFunPtr
{-# INLINE newForeignPtr #-}
newForeignPtr :: MonadIO m => FinalizerPtr a -> Ptr a -> m (ForeignPtr a)
newForeignPtr finalizer p = liftIO (F.newForeignPtr finalizer p)
{-# INLINE newForeignPtr_ #-}
newForeignPtr_ :: MonadIO m => Ptr a -> m (ForeignPtr a)
newForeignPtr_ = liftIO . F.newForeignPtr_
{-# INLINE addForeignPtrFinalizer #-}
addForeignPtrFinalizer :: MonadIO m => FinalizerPtr a -> ForeignPtr a -> m ()
addForeignPtrFinalizer finalizer_ptr foreign_ptr =
liftIO (F.addForeignPtrFinalizer finalizer_ptr foreign_ptr)
{-# INLINE newForeignPtrEnv #-}
newForeignPtrEnv ::
MonadIO m => FinalizerEnvPtr env a -> Ptr env -> Ptr a -> m (ForeignPtr a)
newForeignPtrEnv finalizer env p = liftIO (F.newForeignPtrEnv finalizer env p)
{-# INLINE addForeignPtrFinalizerEnv #-}
addForeignPtrFinalizerEnv ::
MonadIO m => FinalizerEnvPtr env a -> Ptr env -> ForeignPtr a -> m ()
addForeignPtrFinalizerEnv finalizer env fp =
liftIO (F.addForeignPtrFinalizerEnv finalizer env fp)
{-# INLINE withForeignPtr #-}
withForeignPtr :: MonadUnliftIO m => ForeignPtr a -> (Ptr a -> m b) -> m b
withForeignPtr fo io = withRunInIO (\u -> F.withForeignPtr fo (u . io))
{-# INLINE finalizeForeignPtr #-}
finalizeForeignPtr :: MonadIO m => ForeignPtr a -> m ()
finalizeForeignPtr = liftIO . F.finalizeForeignPtr
{-# INLINE touchForeignPtr #-}
touchForeignPtr :: MonadIO m => ForeignPtr a -> m ()
touchForeignPtr = liftIO . F.touchForeignPtr
{-# INLINE mallocForeignPtr #-}
mallocForeignPtr :: (MonadIO m, Storable a) => m (ForeignPtr a)
mallocForeignPtr = liftIO F.mallocForeignPtr
{-# INLINE mallocForeignPtrBytes #-}
mallocForeignPtrBytes :: MonadIO m => Int -> m (ForeignPtr a)
mallocForeignPtrBytes = liftIO . F.mallocForeignPtrBytes
{-# INLINE mallocForeignPtrArray #-}
mallocForeignPtrArray :: (MonadIO m, Storable a) => Int -> m (ForeignPtr a)
mallocForeignPtrArray = liftIO . F.mallocForeignPtrArray
{-# INLINE mallocForeignPtrArray0 #-}
mallocForeignPtrArray0 :: (MonadIO m, Storable a) => Int -> m (ForeignPtr a)
mallocForeignPtrArray0 = liftIO . F.mallocForeignPtrArray0
{-# INLINE newGHCForeignPtr #-}
newGHCForeignPtr :: MonadUnliftIO m => Ptr a -> m () -> m (ForeignPtr a)
newGHCForeignPtr ptr f = withRunInIO (\u -> FC.newForeignPtr ptr (u f))
{-# INLINE addGHCForeignPtrFinalizer #-}
addGHCForeignPtrFinalizer :: MonadUnliftIO m => ForeignPtr a -> m () -> m ()
addGHCForeignPtrFinalizer fptr f =
withRunInIO (\u -> FC.addForeignPtrFinalizer fptr (u f))
{-# INLINE newStablePtr #-}
newStablePtr :: MonadIO m => a -> m (StablePtr a)
newStablePtr = liftIO . F.newStablePtr
{-# INLINE deRefStablePtr #-}
deRefStablePtr :: MonadIO m => StablePtr a -> m a
deRefStablePtr = liftIO . F.deRefStablePtr
{-# INLINE freeStablePtr #-}
freeStablePtr :: MonadIO m => StablePtr a -> m ()
freeStablePtr = liftIO . F.freeStablePtr
{-# INLINE alloca #-}
alloca :: (MonadUnliftIO m, Storable a) => (Ptr a -> m b) -> m b
alloca action = withRunInIO (\u -> F.alloca (u . action))
{-# INLINE allocaBytes #-}
allocaBytes :: MonadUnliftIO m => Int -> (Ptr a -> m b) -> m b
allocaBytes size action = withRunInIO (\u -> F.allocaBytes size (u . action))
{-# INLINE allocaBytesAligned #-}
allocaBytesAligned :: MonadUnliftIO m => Int -> Int -> (Ptr a -> m b) -> m b
allocaBytesAligned size align action =
withRunInIO (\u -> F.allocaBytesAligned size align (u . action))
{-# INLINE malloc #-}
malloc :: (MonadIO m, Storable a) => m (Ptr a)
malloc = liftIO F.malloc
{-# INLINE mallocBytes #-}
mallocBytes :: MonadIO m => Int -> m (Ptr a)
mallocBytes = liftIO . F.mallocBytes
#if MIN_VERSION_base(4,8,0)
{-# INLINE calloc #-}
calloc :: (MonadIO m, Storable a) => m (Ptr a)
calloc = liftIO F.calloc
{-# INLINE callocBytes #-}
callocBytes :: MonadIO m => Int -> m (Ptr a)
callocBytes = liftIO . F.callocBytes
#endif
{-# INLINE realloc #-}
realloc :: (MonadIO m, Storable b) => Ptr a -> m (Ptr b)
realloc = liftIO . F.realloc
{-# INLINE reallocBytes #-}
reallocBytes :: MonadIO m => Ptr a -> Int -> m (Ptr a)
reallocBytes ptr size = liftIO (F.reallocBytes ptr size)
{-# INLINE free #-}
free :: MonadIO m => Ptr a -> m ()
free = liftIO . F.free
{-# INLINE mallocArray #-}
mallocArray :: (MonadIO m, Storable a) => Int -> m (Ptr a)
mallocArray = liftIO . F.mallocArray
{-# INLINE mallocArray0 #-}
mallocArray0 :: (MonadIO m, Storable a) => Int -> m (Ptr a)
mallocArray0 = liftIO . F.mallocArray
{-# INLINE allocaArray #-}
allocaArray :: (MonadUnliftIO m, Storable a) => Int -> (Ptr a -> m b) -> m b
allocaArray size action = withRunInIO (\u -> F.allocaArray size (u . action))
{-# INLINE allocaArray0 #-}
allocaArray0 :: (MonadUnliftIO m, Storable a) => Int -> (Ptr a -> m b) -> m b
allocaArray0 size action = withRunInIO (\u -> F.allocaArray0 size (u . action))
{-# INLINE reallocArray #-}
reallocArray :: (MonadIO m, Storable a) => Ptr a -> Int -> m (Ptr a)
reallocArray ptr size = liftIO (F.reallocArray ptr size)
{-# INLINE reallocArray0 #-}
reallocArray0 :: (MonadIO m, Storable a) => Ptr a -> Int -> m (Ptr a)
reallocArray0 ptr size = liftIO (F.reallocArray0 ptr size)
#if MIN_VERSION_base(4,8,0)
{-# INLINE callocArray #-}
callocArray :: (MonadIO m, Storable a) => Int -> m (Ptr a)
callocArray = liftIO . F.callocArray
{-# INLINE callocArray0 #-}
callocArray0 :: (MonadIO m, Storable a) => Int -> m (Ptr a)
callocArray0 = liftIO . F.callocArray0
#endif
{-# INLINE peekArray #-}
peekArray :: (MonadIO m, Storable a) => Int -> Ptr a -> m [a]
peekArray size ptr = liftIO (F.peekArray size ptr)
{-# INLINE peekArray0 #-}
peekArray0 :: (MonadIO m, Storable a, Eq a) => a -> Ptr a -> m [a]
peekArray0 marker ptr = liftIO (F.peekArray0 marker ptr)
{-# INLINE pokeArray #-}
pokeArray :: (MonadIO m, Storable a) => Ptr a -> [a] -> m ()
pokeArray ptr vals0 = liftIO (F.pokeArray ptr vals0)
{-# INLINE pokeArray0 #-}
pokeArray0 :: (MonadIO m, Storable a) => a -> Ptr a -> [a] -> m ()
pokeArray0 marker ptr vals0 = liftIO (F.pokeArray0 marker ptr vals0)
{-# INLINE newArray #-}
newArray :: (MonadIO m, Storable a) => [a] -> m (Ptr a)
newArray = liftIO . F.newArray
{-# INLINE newArray0 #-}
newArray0 :: (MonadIO m, Storable a) => a -> [a] -> m (Ptr a)
newArray0 marker vals = liftIO (F.newArray0 marker vals)
{-# INLINE withArray #-}
withArray :: (MonadUnliftIO m, Storable a) => [a] -> (Ptr a -> m b) -> m b
withArray vals action = withRunInIO (\u -> F.withArray vals (u . action))
{-# INLINE withArray0 #-}
withArray0 :: (MonadUnliftIO m, Storable a) => a -> [a] -> (Ptr a -> m b) -> m b
withArray0 marker vals action =
withRunInIO (\u -> F.withArray0 marker vals (u . action))
{-# INLINE withArrayLen #-}
withArrayLen ::
(MonadUnliftIO m, Storable a) => [a] -> (Int -> Ptr a -> m b) -> m b
withArrayLen vals f =
withRunInIO (\u -> F.withArrayLen vals (\s p -> u (f s p)))
{-# INLINE withArrayLen0 #-}
withArrayLen0 ::
(MonadUnliftIO m, Storable a) => a -> [a] -> (Int -> Ptr a -> m b) -> m b
withArrayLen0 marker vals f =
withRunInIO (\u -> F.withArrayLen0 marker vals (\s p -> u (f s p)))
{-# INLINE copyArray #-}
copyArray :: (MonadIO m, Storable a) => Ptr a -> Ptr a -> Int -> m ()
copyArray dest src size = liftIO (F.copyArray dest src size)
{-# INLINE moveArray #-}
moveArray :: (MonadIO m, Storable a) => Ptr a -> Ptr a -> Int -> m ()
moveArray dest src size = liftIO (F.moveArray dest src size)
{-# INLINE lengthArray0 #-}
lengthArray0 :: (MonadIO m, Storable a, Eq a) => a -> Ptr a -> m Int
lengthArray0 marker ptr = liftIO (F.lengthArray0 marker ptr)
{-# INLINE throwIf #-}
throwIf :: MonadUnliftIO m => (a -> Bool) -> (a -> String) -> m a -> m a
throwIf pred_ msgfct act = withRunInIO (\u -> F.throwIf pred_ msgfct (u act))
{-# INLINE throwIf_ #-}
throwIf_ :: MonadUnliftIO m => (a -> Bool) -> (a -> String) -> m a -> m ()
throwIf_ pred_ msgfct act = withRunInIO (\u -> F.throwIf_ pred_ msgfct (u act))
{-# INLINE throwIfNeg #-}
throwIfNeg :: (MonadUnliftIO m, Ord a, Num a) => (a -> String) -> m a -> m a
throwIfNeg msgfct act = withRunInIO (\u -> F.throwIfNeg msgfct (u act))
{-# INLINE throwIfNeg_ #-}
throwIfNeg_ :: (MonadUnliftIO m, Ord a, Num a) => (a -> String) -> m a -> m ()
throwIfNeg_ msgfct act = withRunInIO (\u -> F.throwIfNeg_ msgfct (u act))
{-# INLINE throwIfNull #-}
throwIfNull :: MonadUnliftIO m => String -> m (Ptr a) -> m (Ptr a)
throwIfNull msg act = withRunInIO (\u -> F.throwIfNull msg (u act))
{-# INLINE newPool #-}
newPool :: MonadIO m => m Pool
newPool = liftIO F.newPool
{-# INLINE freePool #-}
freePool :: MonadIO m => Pool -> m ()
freePool = liftIO . F.freePool
{-# INLINE withPool #-}
withPool :: MonadUnliftIO m => (Pool -> m b) -> m b
withPool act = withRunInIO (\u -> F.withPool (u . act))
{-# INLINE pooledMalloc #-}
pooledMalloc :: (MonadIO m, Storable a) => Pool -> m (Ptr a)
pooledMalloc = liftIO . F.pooledMalloc
{-# INLINE pooledMallocBytes #-}
pooledMallocBytes :: MonadIO m => Pool -> Int -> m (Ptr a)
pooledMallocBytes pool size = liftIO (F.pooledMallocBytes pool size)
{-# INLINE pooledRealloc #-}
pooledRealloc :: (MonadIO m, Storable a) => Pool -> Ptr a -> m (Ptr a)
pooledRealloc pool ptr = liftIO (F.pooledRealloc pool ptr)
{-# INLINE pooledReallocBytes #-}
pooledReallocBytes :: MonadIO m => Pool -> Ptr a -> Int -> m (Ptr a)
pooledReallocBytes pool ptr size = liftIO (F.pooledReallocBytes pool ptr size)
{-# INLINE pooledMallocArray #-}
pooledMallocArray :: (MonadIO m, Storable a) => Pool -> Int -> m (Ptr a)
pooledMallocArray pool size = liftIO (F.pooledMallocArray pool size)
{-# INLINE pooledMallocArray0 #-}
pooledMallocArray0 :: (MonadIO m, Storable a) => Pool -> Int -> m (Ptr a)
pooledMallocArray0 pool size = liftIO (F.pooledMallocArray0 pool size)
{-# INLINE pooledReallocArray #-}
pooledReallocArray ::
(MonadIO m, Storable a) => Pool -> Ptr a -> Int -> m (Ptr a)
pooledReallocArray pool ptr size = liftIO (F.pooledReallocArray pool ptr size)
{-# INLINE pooledReallocArray0 #-}
pooledReallocArray0 ::
(MonadIO m, Storable a) => Pool -> Ptr a -> Int -> m (Ptr a)
pooledReallocArray0 pool ptr size = liftIO (F.pooledReallocArray0 pool ptr size)
{-# INLINE pooledNew #-}
pooledNew :: (MonadIO m, Storable a) => Pool -> a -> m (Ptr a)
pooledNew pool val = liftIO (F.pooledNew pool val)
{-# INLINE pooledNewArray #-}
pooledNewArray :: (MonadIO m, Storable a) => Pool -> [a] -> m (Ptr a)
pooledNewArray pool vals = liftIO (F.pooledNewArray pool vals)
{-# INLINE pooledNewArray0 #-}
pooledNewArray0 :: (MonadIO m, Storable a) => Pool -> a -> [a] -> m (Ptr a)
pooledNewArray0 pool marker vals = liftIO (F.pooledNewArray0 pool marker vals)
{-# INLINE with #-}
with :: (MonadUnliftIO m, Storable a) => a -> (Ptr a -> m b) -> m b
with val f = withRunInIO (\u -> F.with val (u . f))
{-# INLINE new #-}
new :: (MonadIO m, Storable a) => a -> m (Ptr a)
new = liftIO . F.new
{-# INLINE maybeNew #-}
maybeNew :: MonadIO m => (a -> m (Ptr b)) -> Maybe a -> m (Ptr b)
maybeNew = maybe (return nullPtr)
{-# INLINE maybeWith #-}
maybeWith ::
MonadIO m
=> (a -> (Ptr b -> m c) -> m c)
-> Maybe a
-> (Ptr b -> m c)
-> m c
maybeWith = maybe ($ nullPtr)
{-# INLINE maybePeek #-}
maybePeek :: MonadUnliftIO m => (Ptr a -> m b) -> Ptr a -> m (Maybe b)
maybePeek peek_ ptr = withRunInIO (\u -> F.maybePeek (u . peek_) ptr)
{-# INLINE copyBytes #-}
copyBytes :: MonadIO m => Ptr a -> Ptr a -> Int -> m ()
copyBytes dest src size = liftIO (F.copyBytes dest src size)
{-# INLINE moveBytes #-}
moveBytes :: MonadIO m => Ptr a -> Ptr a -> Int -> m ()
moveBytes dest src size = liftIO (F.moveBytes dest src size)
#if MIN_VERSION_base(4,8,0)
{-# INLINE fillBytes #-}
fillBytes :: MonadIO m => Ptr a -> Word8 -> Int -> m ()
fillBytes dest char size = liftIO (F.fillBytes dest char size)
#endif