{-# 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 :: CString -> m String
peekCString = IO String -> m String
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO String -> m String)
-> (CString -> IO String) -> CString -> m String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CString -> IO String
F.peekCString
{-# INLINE peekCStringLen #-}
peekCStringLen :: MonadIO m => CStringLen -> m String
peekCStringLen :: CStringLen -> m String
peekCStringLen = IO String -> m String
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO String -> m String)
-> (CStringLen -> IO String) -> CStringLen -> m String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CStringLen -> IO String
F.peekCStringLen
{-# INLINE newCString #-}
newCString :: MonadIO m => String -> m CString
newCString :: String -> m CString
newCString = IO CString -> m CString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CString -> m CString)
-> (String -> IO CString) -> String -> m CString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO CString
F.newCString
{-# INLINE newCStringLen #-}
newCStringLen :: MonadIO m => String -> m CStringLen
newCStringLen :: String -> m CStringLen
newCStringLen = IO CStringLen -> m CStringLen
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CStringLen -> m CStringLen)
-> (String -> IO CStringLen) -> String -> m CStringLen
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO CStringLen
F.newCStringLen
{-# INLINE withCString #-}
withCString :: MonadUnliftIO m => String -> (CString -> m a) -> m a
withCString :: String -> (CString -> m a) -> m a
withCString String
s CString -> m a
f = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> (CString -> IO a) -> IO a
forall a. String -> (CString -> IO a) -> IO a
F.withCString String
s (m a -> IO a
forall a. m a -> IO a
u (m a -> IO a) -> (CString -> m a) -> CString -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CString -> m a
f))
{-# INLINE withCStringLen #-}
withCStringLen :: MonadUnliftIO m => String -> (CStringLen -> m a) -> m a
withCStringLen :: String -> (CStringLen -> m a) -> m a
withCStringLen String
s CStringLen -> m a
f = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> (CStringLen -> IO a) -> IO a
forall a. String -> (CStringLen -> IO a) -> IO a
F.withCStringLen String
s (m a -> IO a
forall a. m a -> IO a
u (m a -> IO a) -> (CStringLen -> m a) -> CStringLen -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CStringLen -> m a
f))
{-# INLINE peekCAString #-}
peekCAString :: MonadIO m => CString -> m String
peekCAString :: CString -> m String
peekCAString = IO String -> m String
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO String -> m String)
-> (CString -> IO String) -> CString -> m String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CString -> IO String
F.peekCAString
{-# INLINE peekCAStringLen #-}
peekCAStringLen :: MonadIO m => CStringLen -> m String
peekCAStringLen :: CStringLen -> m String
peekCAStringLen = IO String -> m String
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO String -> m String)
-> (CStringLen -> IO String) -> CStringLen -> m String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CStringLen -> IO String
F.peekCAStringLen
{-# INLINE newCAString #-}
newCAString :: MonadIO m => String -> m CString
newCAString :: String -> m CString
newCAString = IO CString -> m CString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CString -> m CString)
-> (String -> IO CString) -> String -> m CString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO CString
F.newCAString
{-# INLINE newCAStringLen #-}
newCAStringLen :: MonadIO m => String -> m CStringLen
newCAStringLen :: String -> m CStringLen
newCAStringLen = IO CStringLen -> m CStringLen
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CStringLen -> m CStringLen)
-> (String -> IO CStringLen) -> String -> m CStringLen
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO CStringLen
F.newCAStringLen
{-# INLINE withCAString #-}
withCAString :: MonadUnliftIO m => String -> (CString -> m a) -> m a
withCAString :: String -> (CString -> m a) -> m a
withCAString String
str CString -> m a
f = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> (CString -> IO a) -> IO a
forall a. String -> (CString -> IO a) -> IO a
F.withCAString String
str (m a -> IO a
forall a. m a -> IO a
u (m a -> IO a) -> (CString -> m a) -> CString -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CString -> m a
f))
{-# INLINE withCAStringLen #-}
withCAStringLen :: MonadUnliftIO m => String -> (CStringLen -> m a) -> m a
withCAStringLen :: String -> (CStringLen -> m a) -> m a
withCAStringLen String
str CStringLen -> m a
f = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> (CStringLen -> IO a) -> IO a
forall a. String -> (CStringLen -> IO a) -> IO a
F.withCAStringLen String
str (m a -> IO a
forall a. m a -> IO a
u (m a -> IO a) -> (CStringLen -> m a) -> CStringLen -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CStringLen -> m a
f))
{-# INLINE peekCWString #-}
peekCWString :: MonadIO m => CWString -> m String
peekCWString :: CWString -> m String
peekCWString = IO String -> m String
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO String -> m String)
-> (CWString -> IO String) -> CWString -> m String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CWString -> IO String
F.peekCWString
{-# INLINE peekCWStringLen #-}
peekCWStringLen :: MonadIO m => CWStringLen -> m String
peekCWStringLen :: CWStringLen -> m String
peekCWStringLen = IO String -> m String
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO String -> m String)
-> (CWStringLen -> IO String) -> CWStringLen -> m String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CWStringLen -> IO String
F.peekCWStringLen
{-# INLINE newCWString #-}
newCWString :: MonadIO m => String -> m CWString
newCWString :: String -> m CWString
newCWString = IO CWString -> m CWString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CWString -> m CWString)
-> (String -> IO CWString) -> String -> m CWString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO CWString
F.newCWString
{-# INLINE newCWStringLen #-}
newCWStringLen :: MonadIO m => String -> m CWStringLen
newCWStringLen :: String -> m CWStringLen
newCWStringLen = IO CWStringLen -> m CWStringLen
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CWStringLen -> m CWStringLen)
-> (String -> IO CWStringLen) -> String -> m CWStringLen
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO CWStringLen
F.newCWStringLen
{-# INLINE withCWString #-}
withCWString :: MonadUnliftIO m => String -> (CWString -> m a) -> m a
withCWString :: String -> (CWString -> m a) -> m a
withCWString String
str CWString -> m a
f = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> (CWString -> IO a) -> IO a
forall a. String -> (CWString -> IO a) -> IO a
F.withCWString String
str (m a -> IO a
forall a. m a -> IO a
u (m a -> IO a) -> (CWString -> m a) -> CWString -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CWString -> m a
f))
{-# INLINE withCWStringLen #-}
withCWStringLen :: MonadUnliftIO m => String -> (CWStringLen -> m a) -> m a
withCWStringLen :: String -> (CWStringLen -> m a) -> m a
withCWStringLen String
str CWStringLen -> m a
f = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> (CWStringLen -> IO a) -> IO a
forall a. String -> (CWStringLen -> IO a) -> IO a
F.withCWStringLen String
str (m a -> IO a
forall a. m a -> IO a
u (m a -> IO a) -> (CWStringLen -> m a) -> CWStringLen -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CWStringLen -> m a
f))
{-# INLINE getErrno #-}
getErrno :: MonadIO m => m Errno
getErrno :: m Errno
getErrno = IO Errno -> m Errno
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Errno
F.getErrno
{-# INLINE resetErrno #-}
resetErrno :: MonadIO m => m ()
resetErrno :: m ()
resetErrno = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ()
F.resetErrno
{-# INLINE throwErrno #-}
throwErrno :: MonadIO m => String -> m a
throwErrno :: String -> m a
throwErrno = IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> m a) -> (String -> IO a) -> String -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO a
forall a. String -> IO a
F.throwErrno
{-# INLINE throwErrnoIf #-}
throwErrnoIf :: MonadUnliftIO m => (a -> Bool) -> String -> m a -> m a
throwErrnoIf :: (a -> Bool) -> String -> m a -> m a
throwErrnoIf a -> Bool
pred_ String
loc m a
f = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (a -> Bool) -> String -> IO a -> IO a
forall a. (a -> Bool) -> String -> IO a -> IO a
F.throwErrnoIf a -> Bool
pred_ String
loc (m a -> IO a
forall a. m a -> IO a
u m a
f))
{-# INLINE throwErrnoIf_ #-}
throwErrnoIf_ :: MonadUnliftIO m => (a -> Bool) -> String -> m a -> m ()
throwErrnoIf_ :: (a -> Bool) -> String -> m a -> m ()
throwErrnoIf_ a -> Bool
pred_ String
loc m a
f = ((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (a -> Bool) -> String -> IO a -> IO ()
forall a. (a -> Bool) -> String -> IO a -> IO ()
F.throwErrnoIf_ a -> Bool
pred_ String
loc (m a -> IO a
forall a. m a -> IO a
u m a
f))
{-# INLINE throwErrnoIfRetry #-}
throwErrnoIfRetry :: MonadUnliftIO m => (a -> Bool) -> String -> m a -> m a
throwErrnoIfRetry :: (a -> Bool) -> String -> m a -> m a
throwErrnoIfRetry a -> Bool
pred_ String
loc m a
f =
((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (a -> Bool) -> String -> IO a -> IO a
forall a. (a -> Bool) -> String -> IO a -> IO a
F.throwErrnoIfRetry a -> Bool
pred_ String
loc (m a -> IO a
forall a. m a -> IO a
u m a
f))
{-# INLINE throwErrnoIfRetry_ #-}
throwErrnoIfRetry_ :: MonadUnliftIO m => (a -> Bool) -> String -> m a -> m ()
throwErrnoIfRetry_ :: (a -> Bool) -> String -> m a -> m ()
throwErrnoIfRetry_ a -> Bool
pred_ String
loc m a
f =
((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (a -> Bool) -> String -> IO a -> IO ()
forall a. (a -> Bool) -> String -> IO a -> IO ()
F.throwErrnoIfRetry_ a -> Bool
pred_ String
loc (m a -> IO a
forall a. m a -> IO a
u m a
f))
{-# INLINE throwErrnoIfMinus1 #-}
throwErrnoIfMinus1 :: (MonadUnliftIO m, Eq a, Num a) => String -> m a -> m a
throwErrnoIfMinus1 :: String -> m a -> m a
throwErrnoIfMinus1 String
loc m a
f = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> IO a -> IO a
forall a. (Eq a, Num a) => String -> IO a -> IO a
F.throwErrnoIfMinus1 String
loc (m a -> IO a
forall a. m a -> IO a
u m a
f))
{-# INLINE throwErrnoIfMinus1_ #-}
throwErrnoIfMinus1_ :: (MonadUnliftIO m, Eq a, Num a) => String -> m a -> m ()
throwErrnoIfMinus1_ :: String -> m a -> m ()
throwErrnoIfMinus1_ String
loc m a
f = ((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> IO a -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
F.throwErrnoIfMinus1_ String
loc (m a -> IO a
forall a. m a -> IO a
u m a
f))
{-# INLINE throwErrnoIfMinus1Retry #-}
throwErrnoIfMinus1Retry ::
(MonadUnliftIO m, Eq a, Num a) => String -> m a -> m a
throwErrnoIfMinus1Retry :: String -> m a -> m a
throwErrnoIfMinus1Retry String
loc m a
f =
((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> IO a -> IO a
forall a. (Eq a, Num a) => String -> IO a -> IO a
F.throwErrnoIfMinus1Retry String
loc (m a -> IO a
forall a. m a -> IO a
u m a
f))
{-# INLINE throwErrnoIfMinus1Retry_ #-}
throwErrnoIfMinus1Retry_ ::
(MonadUnliftIO m, Eq a, Num a) => String -> m a -> m ()
throwErrnoIfMinus1Retry_ :: String -> m a -> m ()
throwErrnoIfMinus1Retry_ String
loc m a
f =
((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> IO a -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
F.throwErrnoIfMinus1Retry_ String
loc (m a -> IO a
forall a. m a -> IO a
u m a
f))
{-# INLINE throwErrnoIfNull #-}
throwErrnoIfNull :: MonadUnliftIO m => String -> m (Ptr a) -> m (Ptr a)
throwErrnoIfNull :: String -> m (Ptr a) -> m (Ptr a)
throwErrnoIfNull String
loc m (Ptr a)
f = ((forall a. m a -> IO a) -> IO (Ptr a)) -> m (Ptr a)
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> IO (Ptr a) -> IO (Ptr a)
forall a. String -> IO (Ptr a) -> IO (Ptr a)
F.throwErrnoIfNull String
loc (m (Ptr a) -> IO (Ptr a)
forall a. m a -> IO a
u m (Ptr a)
f))
{-# INLINE throwErrnoIfNullRetry #-}
throwErrnoIfNullRetry :: MonadUnliftIO m => String -> m (Ptr a) -> m (Ptr a)
throwErrnoIfNullRetry :: String -> m (Ptr a) -> m (Ptr a)
throwErrnoIfNullRetry String
loc m (Ptr a)
f =
((forall a. m a -> IO a) -> IO (Ptr a)) -> m (Ptr a)
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> IO (Ptr a) -> IO (Ptr a)
forall a. String -> IO (Ptr a) -> IO (Ptr a)
F.throwErrnoIfNullRetry String
loc (m (Ptr a) -> IO (Ptr a)
forall a. m a -> IO a
u m (Ptr a)
f))
{-# INLINE throwErrnoIfRetryMayBlock #-}
throwErrnoIfRetryMayBlock ::
MonadUnliftIO m => (a -> Bool) -> String -> m a -> m b -> m a
throwErrnoIfRetryMayBlock :: (a -> Bool) -> String -> m a -> m b -> m a
throwErrnoIfRetryMayBlock a -> Bool
pred_ String
loc m a
f m b
on_block =
((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (a -> Bool) -> String -> IO a -> IO b -> IO a
forall a b. (a -> Bool) -> String -> IO a -> IO b -> IO a
F.throwErrnoIfRetryMayBlock a -> Bool
pred_ String
loc (m a -> IO a
forall a. m a -> IO a
u m a
f) (m b -> IO b
forall a. m a -> IO a
u m b
on_block))
{-# INLINE throwErrnoIfRetryMayBlock_ #-}
throwErrnoIfRetryMayBlock_ ::
MonadUnliftIO m => (a -> Bool) -> String -> m a -> m b -> m ()
throwErrnoIfRetryMayBlock_ :: (a -> Bool) -> String -> m a -> m b -> m ()
throwErrnoIfRetryMayBlock_ a -> Bool
pred_ String
loc m a
f m b
on_block =
((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (a -> Bool) -> String -> IO a -> IO b -> IO ()
forall a b. (a -> Bool) -> String -> IO a -> IO b -> IO ()
F.throwErrnoIfRetryMayBlock_ a -> Bool
pred_ String
loc (m a -> IO a
forall a. m a -> IO a
u m a
f) (m b -> IO b
forall a. m a -> IO a
u m b
on_block))
{-# INLINE throwErrnoIfMinus1RetryMayBlock #-}
throwErrnoIfMinus1RetryMayBlock ::
(MonadUnliftIO m, Eq a, Num a) => String -> m a -> m b -> m a
throwErrnoIfMinus1RetryMayBlock :: String -> m a -> m b -> m a
throwErrnoIfMinus1RetryMayBlock String
loc m a
f m b
on_block =
((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> IO a -> IO b -> IO a
forall a b. (Eq a, Num a) => String -> IO a -> IO b -> IO a
F.throwErrnoIfMinus1RetryMayBlock String
loc (m a -> IO a
forall a. m a -> IO a
u m a
f) (m b -> IO b
forall a. m a -> IO a
u m b
on_block))
{-# INLINE throwErrnoIfMinus1RetryMayBlock_ #-}
throwErrnoIfMinus1RetryMayBlock_ ::
(MonadUnliftIO m, Eq a, Num a) => String -> m a -> m b -> m ()
throwErrnoIfMinus1RetryMayBlock_ :: String -> m a -> m b -> m ()
throwErrnoIfMinus1RetryMayBlock_ String
loc m a
f m b
on_block =
((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> IO a -> IO b -> IO ()
forall a b. (Eq a, Num a) => String -> IO a -> IO b -> IO ()
F.throwErrnoIfMinus1RetryMayBlock_ String
loc (m a -> IO a
forall a. m a -> IO a
u m a
f) (m b -> IO b
forall a. m a -> IO a
u m b
on_block))
{-# INLINE throwErrnoIfNullRetryMayBlock #-}
throwErrnoIfNullRetryMayBlock ::
MonadUnliftIO m => String -> m (Ptr a) -> m b -> m (Ptr a)
throwErrnoIfNullRetryMayBlock :: String -> m (Ptr a) -> m b -> m (Ptr a)
throwErrnoIfNullRetryMayBlock String
loc m (Ptr a)
f m b
on_block =
((forall a. m a -> IO a) -> IO (Ptr a)) -> m (Ptr a)
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> IO (Ptr a) -> IO b -> IO (Ptr a)
forall a b. String -> IO (Ptr a) -> IO b -> IO (Ptr a)
F.throwErrnoIfNullRetryMayBlock String
loc (m (Ptr a) -> IO (Ptr a)
forall a. m a -> IO a
u m (Ptr a)
f) (m b -> IO b
forall a. m a -> IO a
u m b
on_block))
{-# INLINE throwErrnoPath #-}
throwErrnoPath :: MonadIO m => String -> FilePath -> m a
throwErrnoPath :: String -> String -> m a
throwErrnoPath String
loc String
path = IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String -> String -> IO a
forall a. String -> String -> IO a
F.throwErrnoPath String
loc String
path)
{-# INLINE throwErrnoPathIf #-}
throwErrnoPathIf ::
MonadUnliftIO m => (a -> Bool) -> String -> FilePath -> m a -> m a
throwErrnoPathIf :: (a -> Bool) -> String -> String -> m a -> m a
throwErrnoPathIf a -> Bool
pred_ String
loc String
path m a
f =
((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (a -> Bool) -> String -> String -> IO a -> IO a
forall a. (a -> Bool) -> String -> String -> IO a -> IO a
F.throwErrnoPathIf a -> Bool
pred_ String
loc String
path (m a -> IO a
forall a. m a -> IO a
u m a
f))
{-# INLINE throwErrnoPathIf_ #-}
throwErrnoPathIf_ ::
MonadUnliftIO m => (a -> Bool) -> String -> FilePath -> m a -> m ()
throwErrnoPathIf_ :: (a -> Bool) -> String -> String -> m a -> m ()
throwErrnoPathIf_ a -> Bool
pred_ String
loc String
path m a
f =
((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (a -> Bool) -> String -> String -> IO a -> IO ()
forall a. (a -> Bool) -> String -> String -> IO a -> IO ()
F.throwErrnoPathIf_ a -> Bool
pred_ String
loc String
path (m a -> IO a
forall a. m a -> IO a
u m a
f))
{-# INLINE throwErrnoPathIfNull #-}
throwErrnoPathIfNull ::
MonadUnliftIO m => String -> FilePath -> m (Ptr a) -> m (Ptr a)
throwErrnoPathIfNull :: String -> String -> m (Ptr a) -> m (Ptr a)
throwErrnoPathIfNull String
loc String
path m (Ptr a)
f =
((forall a. m a -> IO a) -> IO (Ptr a)) -> m (Ptr a)
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> String -> IO (Ptr a) -> IO (Ptr a)
forall a. String -> String -> IO (Ptr a) -> IO (Ptr a)
F.throwErrnoPathIfNull String
loc String
path (m (Ptr a) -> IO (Ptr a)
forall a. m a -> IO a
u m (Ptr a)
f))
{-# INLINE throwErrnoPathIfMinus1 #-}
throwErrnoPathIfMinus1 ::
(MonadUnliftIO m, Eq a, Num a) => String -> FilePath -> m a -> m a
throwErrnoPathIfMinus1 :: String -> String -> m a -> m a
throwErrnoPathIfMinus1 String
loc String
path m a
f =
((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> String -> IO a -> IO a
forall a. (Eq a, Num a) => String -> String -> IO a -> IO a
F.throwErrnoPathIfMinus1 String
loc String
path (m a -> IO a
forall a. m a -> IO a
u m a
f))
{-# INLINE throwErrnoPathIfMinus1_ #-}
throwErrnoPathIfMinus1_ ::
(MonadUnliftIO m, Eq a, Num a) => String -> FilePath -> m a -> m ()
throwErrnoPathIfMinus1_ :: String -> String -> m a -> m ()
throwErrnoPathIfMinus1_ String
loc String
path m a
f =
((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> String -> IO a -> IO ()
forall a. (Eq a, Num a) => String -> String -> IO a -> IO ()
F.throwErrnoPathIfMinus1_ String
loc String
path (m a -> IO a
forall a. m a -> IO a
u m a
f))
{-# INLINE freeHaskellFunPtr #-}
freeHaskellFunPtr :: MonadIO m => FunPtr a -> m ()
freeHaskellFunPtr :: FunPtr a -> m ()
freeHaskellFunPtr = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (FunPtr a -> IO ()) -> FunPtr a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FunPtr a -> IO ()
forall a. FunPtr a -> IO ()
F.freeHaskellFunPtr
{-# INLINE newForeignPtr #-}
newForeignPtr :: MonadIO m => FinalizerPtr a -> Ptr a -> m (ForeignPtr a)
newForeignPtr :: FinalizerPtr a -> Ptr a -> m (ForeignPtr a)
newForeignPtr FinalizerPtr a
finalizer Ptr a
p = IO (ForeignPtr a) -> m (ForeignPtr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
F.newForeignPtr FinalizerPtr a
finalizer Ptr a
p)
{-# INLINE newForeignPtr_ #-}
newForeignPtr_ :: MonadIO m => Ptr a -> m (ForeignPtr a)
newForeignPtr_ :: Ptr a -> m (ForeignPtr a)
newForeignPtr_ = IO (ForeignPtr a) -> m (ForeignPtr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (ForeignPtr a) -> m (ForeignPtr a))
-> (Ptr a -> IO (ForeignPtr a)) -> Ptr a -> m (ForeignPtr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> IO (ForeignPtr a)
forall a. Ptr a -> IO (ForeignPtr a)
F.newForeignPtr_
{-# INLINE addForeignPtrFinalizer #-}
addForeignPtrFinalizer :: MonadIO m => FinalizerPtr a -> ForeignPtr a -> m ()
addForeignPtrFinalizer :: FinalizerPtr a -> ForeignPtr a -> m ()
addForeignPtrFinalizer FinalizerPtr a
finalizer_ptr ForeignPtr a
foreign_ptr =
IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (FinalizerPtr a -> ForeignPtr a -> IO ()
forall a. FinalizerPtr a -> ForeignPtr a -> IO ()
F.addForeignPtrFinalizer FinalizerPtr a
finalizer_ptr ForeignPtr a
foreign_ptr)
{-# INLINE newForeignPtrEnv #-}
newForeignPtrEnv ::
MonadIO m => FinalizerEnvPtr env a -> Ptr env -> Ptr a -> m (ForeignPtr a)
newForeignPtrEnv :: FinalizerEnvPtr env a -> Ptr env -> Ptr a -> m (ForeignPtr a)
newForeignPtrEnv FinalizerEnvPtr env a
finalizer Ptr env
env Ptr a
p = IO (ForeignPtr a) -> m (ForeignPtr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (FinalizerEnvPtr env a -> Ptr env -> Ptr a -> IO (ForeignPtr a)
forall env a.
FinalizerEnvPtr env a -> Ptr env -> Ptr a -> IO (ForeignPtr a)
F.newForeignPtrEnv FinalizerEnvPtr env a
finalizer Ptr env
env Ptr a
p)
{-# INLINE addForeignPtrFinalizerEnv #-}
addForeignPtrFinalizerEnv ::
MonadIO m => FinalizerEnvPtr env a -> Ptr env -> ForeignPtr a -> m ()
addForeignPtrFinalizerEnv :: FinalizerEnvPtr env a -> Ptr env -> ForeignPtr a -> m ()
addForeignPtrFinalizerEnv FinalizerEnvPtr env a
finalizer Ptr env
env ForeignPtr a
fp =
IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (FinalizerEnvPtr env a -> Ptr env -> ForeignPtr a -> IO ()
forall env a.
FinalizerEnvPtr env a -> Ptr env -> ForeignPtr a -> IO ()
F.addForeignPtrFinalizerEnv FinalizerEnvPtr env a
finalizer Ptr env
env ForeignPtr a
fp)
{-# INLINE withForeignPtr #-}
withForeignPtr :: MonadUnliftIO m => ForeignPtr a -> (Ptr a -> m b) -> m b
withForeignPtr :: ForeignPtr a -> (Ptr a -> m b) -> m b
withForeignPtr ForeignPtr a
fo Ptr a -> m b
io = ((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> ForeignPtr a -> (Ptr a -> IO b) -> IO b
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
F.withForeignPtr ForeignPtr a
fo (m b -> IO b
forall a. m a -> IO a
u (m b -> IO b) -> (Ptr a -> m b) -> Ptr a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> m b
io))
{-# INLINE finalizeForeignPtr #-}
finalizeForeignPtr :: MonadIO m => ForeignPtr a -> m ()
finalizeForeignPtr :: ForeignPtr a -> m ()
finalizeForeignPtr = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (ForeignPtr a -> IO ()) -> ForeignPtr a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForeignPtr a -> IO ()
forall a. ForeignPtr a -> IO ()
F.finalizeForeignPtr
{-# INLINE touchForeignPtr #-}
touchForeignPtr :: MonadIO m => ForeignPtr a -> m ()
touchForeignPtr :: ForeignPtr a -> m ()
touchForeignPtr = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (ForeignPtr a -> IO ()) -> ForeignPtr a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForeignPtr a -> IO ()
forall a. ForeignPtr a -> IO ()
F.touchForeignPtr
{-# INLINE mallocForeignPtr #-}
mallocForeignPtr :: (MonadIO m, Storable a) => m (ForeignPtr a)
mallocForeignPtr :: m (ForeignPtr a)
mallocForeignPtr = IO (ForeignPtr a) -> m (ForeignPtr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (ForeignPtr a)
forall a. Storable a => IO (ForeignPtr a)
F.mallocForeignPtr
{-# INLINE mallocForeignPtrBytes #-}
mallocForeignPtrBytes :: MonadIO m => Int -> m (ForeignPtr a)
mallocForeignPtrBytes :: Int -> m (ForeignPtr a)
mallocForeignPtrBytes = IO (ForeignPtr a) -> m (ForeignPtr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (ForeignPtr a) -> m (ForeignPtr a))
-> (Int -> IO (ForeignPtr a)) -> Int -> m (ForeignPtr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IO (ForeignPtr a)
forall a. Int -> IO (ForeignPtr a)
F.mallocForeignPtrBytes
{-# INLINE mallocForeignPtrArray #-}
mallocForeignPtrArray :: (MonadIO m, Storable a) => Int -> m (ForeignPtr a)
mallocForeignPtrArray :: Int -> m (ForeignPtr a)
mallocForeignPtrArray = IO (ForeignPtr a) -> m (ForeignPtr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (ForeignPtr a) -> m (ForeignPtr a))
-> (Int -> IO (ForeignPtr a)) -> Int -> m (ForeignPtr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IO (ForeignPtr a)
forall a. Storable a => Int -> IO (ForeignPtr a)
F.mallocForeignPtrArray
{-# INLINE mallocForeignPtrArray0 #-}
mallocForeignPtrArray0 :: (MonadIO m, Storable a) => Int -> m (ForeignPtr a)
mallocForeignPtrArray0 :: Int -> m (ForeignPtr a)
mallocForeignPtrArray0 = IO (ForeignPtr a) -> m (ForeignPtr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (ForeignPtr a) -> m (ForeignPtr a))
-> (Int -> IO (ForeignPtr a)) -> Int -> m (ForeignPtr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IO (ForeignPtr a)
forall a. Storable a => Int -> IO (ForeignPtr a)
F.mallocForeignPtrArray0
{-# INLINE newGHCForeignPtr #-}
newGHCForeignPtr :: MonadUnliftIO m => Ptr a -> m () -> m (ForeignPtr a)
newGHCForeignPtr :: Ptr a -> m () -> m (ForeignPtr a)
newGHCForeignPtr Ptr a
ptr m ()
f = ((forall a. m a -> IO a) -> IO (ForeignPtr a)) -> m (ForeignPtr a)
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> Ptr a -> IO () -> IO (ForeignPtr a)
forall a. Ptr a -> IO () -> IO (ForeignPtr a)
FC.newForeignPtr Ptr a
ptr (m () -> IO ()
forall a. m a -> IO a
u m ()
f))
{-# INLINE addGHCForeignPtrFinalizer #-}
addGHCForeignPtrFinalizer :: MonadUnliftIO m => ForeignPtr a -> m () -> m ()
addGHCForeignPtrFinalizer :: ForeignPtr a -> m () -> m ()
addGHCForeignPtrFinalizer ForeignPtr a
fptr m ()
f =
((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> ForeignPtr a -> IO () -> IO ()
forall a. ForeignPtr a -> IO () -> IO ()
FC.addForeignPtrFinalizer ForeignPtr a
fptr (m () -> IO ()
forall a. m a -> IO a
u m ()
f))
{-# INLINE newStablePtr #-}
newStablePtr :: MonadIO m => a -> m (StablePtr a)
newStablePtr :: a -> m (StablePtr a)
newStablePtr = IO (StablePtr a) -> m (StablePtr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (StablePtr a) -> m (StablePtr a))
-> (a -> IO (StablePtr a)) -> a -> m (StablePtr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> IO (StablePtr a)
forall a. a -> IO (StablePtr a)
F.newStablePtr
{-# INLINE deRefStablePtr #-}
deRefStablePtr :: MonadIO m => StablePtr a -> m a
deRefStablePtr :: StablePtr a -> m a
deRefStablePtr = IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> m a) -> (StablePtr a -> IO a) -> StablePtr a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StablePtr a -> IO a
forall a. StablePtr a -> IO a
F.deRefStablePtr
{-# INLINE freeStablePtr #-}
freeStablePtr :: MonadIO m => StablePtr a -> m ()
freeStablePtr :: StablePtr a -> m ()
freeStablePtr = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (StablePtr a -> IO ()) -> StablePtr a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StablePtr a -> IO ()
forall a. StablePtr a -> IO ()
F.freeStablePtr
{-# INLINE alloca #-}
alloca :: (MonadUnliftIO m, Storable a) => (Ptr a -> m b) -> m b
alloca :: (Ptr a -> m b) -> m b
alloca Ptr a -> m b
action = ((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (Ptr a -> IO b) -> IO b
forall a b. Storable a => (Ptr a -> IO b) -> IO b
F.alloca (m b -> IO b
forall a. m a -> IO a
u (m b -> IO b) -> (Ptr a -> m b) -> Ptr a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> m b
action))
{-# INLINE allocaBytes #-}
allocaBytes :: MonadUnliftIO m => Int -> (Ptr a -> m b) -> m b
allocaBytes :: Int -> (Ptr a -> m b) -> m b
allocaBytes Int
size Ptr a -> m b
action = ((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> Int -> (Ptr a -> IO b) -> IO b
forall a b. Int -> (Ptr a -> IO b) -> IO b
F.allocaBytes Int
size (m b -> IO b
forall a. m a -> IO a
u (m b -> IO b) -> (Ptr a -> m b) -> Ptr a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> m b
action))
{-# INLINE allocaBytesAligned #-}
allocaBytesAligned :: MonadUnliftIO m => Int -> Int -> (Ptr a -> m b) -> m b
allocaBytesAligned :: Int -> Int -> (Ptr a -> m b) -> m b
allocaBytesAligned Int
size Int
align Ptr a -> m b
action =
((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> Int -> Int -> (Ptr a -> IO b) -> IO b
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
F.allocaBytesAligned Int
size Int
align (m b -> IO b
forall a. m a -> IO a
u (m b -> IO b) -> (Ptr a -> m b) -> Ptr a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> m b
action))
{-# INLINE malloc #-}
malloc :: (MonadIO m, Storable a) => m (Ptr a)
malloc :: m (Ptr a)
malloc = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (Ptr a)
forall a. Storable a => IO (Ptr a)
F.malloc
{-# INLINE mallocBytes #-}
mallocBytes :: MonadIO m => Int -> m (Ptr a)
mallocBytes :: Int -> m (Ptr a)
mallocBytes = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr a) -> m (Ptr a))
-> (Int -> IO (Ptr a)) -> Int -> m (Ptr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IO (Ptr a)
forall a. Int -> IO (Ptr a)
F.mallocBytes
#if MIN_VERSION_base(4,8,0)
{-# INLINE calloc #-}
calloc :: (MonadIO m, Storable a) => m (Ptr a)
calloc :: m (Ptr a)
calloc = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (Ptr a)
forall a. Storable a => IO (Ptr a)
F.calloc
{-# INLINE callocBytes #-}
callocBytes :: MonadIO m => Int -> m (Ptr a)
callocBytes :: Int -> m (Ptr a)
callocBytes = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr a) -> m (Ptr a))
-> (Int -> IO (Ptr a)) -> Int -> m (Ptr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IO (Ptr a)
forall a. Int -> IO (Ptr a)
F.callocBytes
#endif
{-# INLINE realloc #-}
realloc :: (MonadIO m, Storable b) => Ptr a -> m (Ptr b)
realloc :: Ptr a -> m (Ptr b)
realloc = IO (Ptr b) -> m (Ptr b)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr b) -> m (Ptr b))
-> (Ptr a -> IO (Ptr b)) -> Ptr a -> m (Ptr b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> IO (Ptr b)
forall a b. Storable b => Ptr a -> IO (Ptr b)
F.realloc
{-# INLINE reallocBytes #-}
reallocBytes :: MonadIO m => Ptr a -> Int -> m (Ptr a)
reallocBytes :: Ptr a -> Int -> m (Ptr a)
reallocBytes Ptr a
ptr Int
size = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Ptr a -> Int -> IO (Ptr a)
forall a. Ptr a -> Int -> IO (Ptr a)
F.reallocBytes Ptr a
ptr Int
size)
{-# INLINE free #-}
free :: MonadIO m => Ptr a -> m ()
free :: Ptr a -> m ()
free = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (Ptr a -> IO ()) -> Ptr a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> IO ()
forall a. Ptr a -> IO ()
F.free
{-# INLINE mallocArray #-}
mallocArray :: (MonadIO m, Storable a) => Int -> m (Ptr a)
mallocArray :: Int -> m (Ptr a)
mallocArray = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr a) -> m (Ptr a))
-> (Int -> IO (Ptr a)) -> Int -> m (Ptr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IO (Ptr a)
forall a. Storable a => Int -> IO (Ptr a)
F.mallocArray
{-# INLINE mallocArray0 #-}
mallocArray0 :: (MonadIO m, Storable a) => Int -> m (Ptr a)
mallocArray0 :: Int -> m (Ptr a)
mallocArray0 = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr a) -> m (Ptr a))
-> (Int -> IO (Ptr a)) -> Int -> m (Ptr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IO (Ptr a)
forall a. Storable a => Int -> IO (Ptr a)
F.mallocArray
{-# INLINE allocaArray #-}
allocaArray :: (MonadUnliftIO m, Storable a) => Int -> (Ptr a -> m b) -> m b
allocaArray :: Int -> (Ptr a -> m b) -> m b
allocaArray Int
size Ptr a -> m b
action = ((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> Int -> (Ptr a -> IO b) -> IO b
forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
F.allocaArray Int
size (m b -> IO b
forall a. m a -> IO a
u (m b -> IO b) -> (Ptr a -> m b) -> Ptr a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> m b
action))
{-# INLINE allocaArray0 #-}
allocaArray0 :: (MonadUnliftIO m, Storable a) => Int -> (Ptr a -> m b) -> m b
allocaArray0 :: Int -> (Ptr a -> m b) -> m b
allocaArray0 Int
size Ptr a -> m b
action = ((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> Int -> (Ptr a -> IO b) -> IO b
forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
F.allocaArray0 Int
size (m b -> IO b
forall a. m a -> IO a
u (m b -> IO b) -> (Ptr a -> m b) -> Ptr a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> m b
action))
{-# INLINE reallocArray #-}
reallocArray :: (MonadIO m, Storable a) => Ptr a -> Int -> m (Ptr a)
reallocArray :: Ptr a -> Int -> m (Ptr a)
reallocArray Ptr a
ptr Int
size = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Ptr a -> Int -> IO (Ptr a)
forall a. Storable a => Ptr a -> Int -> IO (Ptr a)
F.reallocArray Ptr a
ptr Int
size)
{-# INLINE reallocArray0 #-}
reallocArray0 :: (MonadIO m, Storable a) => Ptr a -> Int -> m (Ptr a)
reallocArray0 :: Ptr a -> Int -> m (Ptr a)
reallocArray0 Ptr a
ptr Int
size = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Ptr a -> Int -> IO (Ptr a)
forall a. Storable a => Ptr a -> Int -> IO (Ptr a)
F.reallocArray0 Ptr a
ptr Int
size)
#if MIN_VERSION_base(4,8,0)
{-# INLINE callocArray #-}
callocArray :: (MonadIO m, Storable a) => Int -> m (Ptr a)
callocArray :: Int -> m (Ptr a)
callocArray = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr a) -> m (Ptr a))
-> (Int -> IO (Ptr a)) -> Int -> m (Ptr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IO (Ptr a)
forall a. Storable a => Int -> IO (Ptr a)
F.callocArray
{-# INLINE callocArray0 #-}
callocArray0 :: (MonadIO m, Storable a) => Int -> m (Ptr a)
callocArray0 :: Int -> m (Ptr a)
callocArray0 = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr a) -> m (Ptr a))
-> (Int -> IO (Ptr a)) -> Int -> m (Ptr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IO (Ptr a)
forall a. Storable a => Int -> IO (Ptr a)
F.callocArray0
#endif
{-# INLINE peekArray #-}
peekArray :: (MonadIO m, Storable a) => Int -> Ptr a -> m [a]
peekArray :: Int -> Ptr a -> m [a]
peekArray Int
size Ptr a
ptr = IO [a] -> m [a]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Int -> Ptr a -> IO [a]
forall a. Storable a => Int -> Ptr a -> IO [a]
F.peekArray Int
size Ptr a
ptr)
{-# INLINE peekArray0 #-}
peekArray0 :: (MonadIO m, Storable a, Eq a) => a -> Ptr a -> m [a]
peekArray0 :: a -> Ptr a -> m [a]
peekArray0 a
marker Ptr a
ptr = IO [a] -> m [a]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (a -> Ptr a -> IO [a]
forall a. (Storable a, Eq a) => a -> Ptr a -> IO [a]
F.peekArray0 a
marker Ptr a
ptr)
{-# INLINE pokeArray #-}
pokeArray :: (MonadIO m, Storable a) => Ptr a -> [a] -> m ()
pokeArray :: Ptr a -> [a] -> m ()
pokeArray Ptr a
ptr [a]
vals0 = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Ptr a -> [a] -> IO ()
forall a. Storable a => Ptr a -> [a] -> IO ()
F.pokeArray Ptr a
ptr [a]
vals0)
{-# INLINE pokeArray0 #-}
pokeArray0 :: (MonadIO m, Storable a) => a -> Ptr a -> [a] -> m ()
pokeArray0 :: a -> Ptr a -> [a] -> m ()
pokeArray0 a
marker Ptr a
ptr [a]
vals0 = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (a -> Ptr a -> [a] -> IO ()
forall a. Storable a => a -> Ptr a -> [a] -> IO ()
F.pokeArray0 a
marker Ptr a
ptr [a]
vals0)
{-# INLINE newArray #-}
newArray :: (MonadIO m, Storable a) => [a] -> m (Ptr a)
newArray :: [a] -> m (Ptr a)
newArray = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr a) -> m (Ptr a))
-> ([a] -> IO (Ptr a)) -> [a] -> m (Ptr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> IO (Ptr a)
forall a. Storable a => [a] -> IO (Ptr a)
F.newArray
{-# INLINE newArray0 #-}
newArray0 :: (MonadIO m, Storable a) => a -> [a] -> m (Ptr a)
newArray0 :: a -> [a] -> m (Ptr a)
newArray0 a
marker [a]
vals = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (a -> [a] -> IO (Ptr a)
forall a. Storable a => a -> [a] -> IO (Ptr a)
F.newArray0 a
marker [a]
vals)
{-# INLINE withArray #-}
withArray :: (MonadUnliftIO m, Storable a) => [a] -> (Ptr a -> m b) -> m b
withArray :: [a] -> (Ptr a -> m b) -> m b
withArray [a]
vals Ptr a -> m b
action = ((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> [a] -> (Ptr a -> IO b) -> IO b
forall a b. Storable a => [a] -> (Ptr a -> IO b) -> IO b
F.withArray [a]
vals (m b -> IO b
forall a. m a -> IO a
u (m b -> IO b) -> (Ptr a -> m b) -> Ptr a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> m b
action))
{-# INLINE withArray0 #-}
withArray0 :: (MonadUnliftIO m, Storable a) => a -> [a] -> (Ptr a -> m b) -> m b
withArray0 :: a -> [a] -> (Ptr a -> m b) -> m b
withArray0 a
marker [a]
vals Ptr a -> m b
action =
((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> a -> [a] -> (Ptr a -> IO b) -> IO b
forall a b. Storable a => a -> [a] -> (Ptr a -> IO b) -> IO b
F.withArray0 a
marker [a]
vals (m b -> IO b
forall a. m a -> IO a
u (m b -> IO b) -> (Ptr a -> m b) -> Ptr a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> m b
action))
{-# INLINE withArrayLen #-}
withArrayLen ::
(MonadUnliftIO m, Storable a) => [a] -> (Int -> Ptr a -> m b) -> m b
withArrayLen :: [a] -> (Int -> Ptr a -> m b) -> m b
withArrayLen [a]
vals Int -> Ptr a -> m b
f =
((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> [a] -> (Int -> Ptr a -> IO b) -> IO b
forall a b. Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
F.withArrayLen [a]
vals (\Int
s Ptr a
p -> m b -> IO b
forall a. m a -> IO a
u (Int -> Ptr a -> m b
f Int
s Ptr a
p)))
{-# INLINE withArrayLen0 #-}
withArrayLen0 ::
(MonadUnliftIO m, Storable a) => a -> [a] -> (Int -> Ptr a -> m b) -> m b
withArrayLen0 :: a -> [a] -> (Int -> Ptr a -> m b) -> m b
withArrayLen0 a
marker [a]
vals Int -> Ptr a -> m b
f =
((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> a -> [a] -> (Int -> Ptr a -> IO b) -> IO b
forall a b.
Storable a =>
a -> [a] -> (Int -> Ptr a -> IO b) -> IO b
F.withArrayLen0 a
marker [a]
vals (\Int
s Ptr a
p -> m b -> IO b
forall a. m a -> IO a
u (Int -> Ptr a -> m b
f Int
s Ptr a
p)))
{-# INLINE copyArray #-}
copyArray :: (MonadIO m, Storable a) => Ptr a -> Ptr a -> Int -> m ()
copyArray :: Ptr a -> Ptr a -> Int -> m ()
copyArray Ptr a
dest Ptr a
src Int
size = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Ptr a -> Ptr a -> Int -> IO ()
forall a. Storable a => Ptr a -> Ptr a -> Int -> IO ()
F.copyArray Ptr a
dest Ptr a
src Int
size)
{-# INLINE moveArray #-}
moveArray :: (MonadIO m, Storable a) => Ptr a -> Ptr a -> Int -> m ()
moveArray :: Ptr a -> Ptr a -> Int -> m ()
moveArray Ptr a
dest Ptr a
src Int
size = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Ptr a -> Ptr a -> Int -> IO ()
forall a. Storable a => Ptr a -> Ptr a -> Int -> IO ()
F.moveArray Ptr a
dest Ptr a
src Int
size)
{-# INLINE lengthArray0 #-}
lengthArray0 :: (MonadIO m, Storable a, Eq a) => a -> Ptr a -> m Int
lengthArray0 :: a -> Ptr a -> m Int
lengthArray0 a
marker Ptr a
ptr = IO Int -> m Int
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (a -> Ptr a -> IO Int
forall a. (Storable a, Eq a) => a -> Ptr a -> IO Int
F.lengthArray0 a
marker Ptr a
ptr)
{-# INLINE throwIf #-}
throwIf :: MonadUnliftIO m => (a -> Bool) -> (a -> String) -> m a -> m a
throwIf :: (a -> Bool) -> (a -> String) -> m a -> m a
throwIf a -> Bool
pred_ a -> String
msgfct m a
act = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (a -> Bool) -> (a -> String) -> IO a -> IO a
forall a. (a -> Bool) -> (a -> String) -> IO a -> IO a
F.throwIf a -> Bool
pred_ a -> String
msgfct (m a -> IO a
forall a. m a -> IO a
u m a
act))
{-# INLINE throwIf_ #-}
throwIf_ :: MonadUnliftIO m => (a -> Bool) -> (a -> String) -> m a -> m ()
throwIf_ :: (a -> Bool) -> (a -> String) -> m a -> m ()
throwIf_ a -> Bool
pred_ a -> String
msgfct m a
act = ((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (a -> Bool) -> (a -> String) -> IO a -> IO ()
forall a. (a -> Bool) -> (a -> String) -> IO a -> IO ()
F.throwIf_ a -> Bool
pred_ a -> String
msgfct (m a -> IO a
forall a. m a -> IO a
u m a
act))
{-# INLINE throwIfNeg #-}
throwIfNeg :: (MonadUnliftIO m, Ord a, Num a) => (a -> String) -> m a -> m a
throwIfNeg :: (a -> String) -> m a -> m a
throwIfNeg a -> String
msgfct m a
act = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (a -> String) -> IO a -> IO a
forall a. (Ord a, Num a) => (a -> String) -> IO a -> IO a
F.throwIfNeg a -> String
msgfct (m a -> IO a
forall a. m a -> IO a
u m a
act))
{-# INLINE throwIfNeg_ #-}
throwIfNeg_ :: (MonadUnliftIO m, Ord a, Num a) => (a -> String) -> m a -> m ()
throwIfNeg_ :: (a -> String) -> m a -> m ()
throwIfNeg_ a -> String
msgfct m a
act = ((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (a -> String) -> IO a -> IO ()
forall a. (Ord a, Num a) => (a -> String) -> IO a -> IO ()
F.throwIfNeg_ a -> String
msgfct (m a -> IO a
forall a. m a -> IO a
u m a
act))
{-# INLINE throwIfNull #-}
throwIfNull :: MonadUnliftIO m => String -> m (Ptr a) -> m (Ptr a)
throwIfNull :: String -> m (Ptr a) -> m (Ptr a)
throwIfNull String
msg m (Ptr a)
act = ((forall a. m a -> IO a) -> IO (Ptr a)) -> m (Ptr a)
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> IO (Ptr a) -> IO (Ptr a)
forall a. String -> IO (Ptr a) -> IO (Ptr a)
F.throwIfNull String
msg (m (Ptr a) -> IO (Ptr a)
forall a. m a -> IO a
u m (Ptr a)
act))
{-# INLINE newPool #-}
newPool :: MonadIO m => m Pool
newPool :: m Pool
newPool = IO Pool -> m Pool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Pool
F.newPool
{-# INLINE freePool #-}
freePool :: MonadIO m => Pool -> m ()
freePool :: Pool -> m ()
freePool = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (Pool -> IO ()) -> Pool -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pool -> IO ()
F.freePool
{-# INLINE withPool #-}
withPool :: MonadUnliftIO m => (Pool -> m b) -> m b
withPool :: (Pool -> m b) -> m b
withPool Pool -> m b
act = ((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (Pool -> IO b) -> IO b
forall b. (Pool -> IO b) -> IO b
F.withPool (m b -> IO b
forall a. m a -> IO a
u (m b -> IO b) -> (Pool -> m b) -> Pool -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pool -> m b
act))
{-# INLINE pooledMalloc #-}
pooledMalloc :: (MonadIO m, Storable a) => Pool -> m (Ptr a)
pooledMalloc :: Pool -> m (Ptr a)
pooledMalloc = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr a) -> m (Ptr a))
-> (Pool -> IO (Ptr a)) -> Pool -> m (Ptr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pool -> IO (Ptr a)
forall a. Storable a => Pool -> IO (Ptr a)
F.pooledMalloc
{-# INLINE pooledMallocBytes #-}
pooledMallocBytes :: MonadIO m => Pool -> Int -> m (Ptr a)
pooledMallocBytes :: Pool -> Int -> m (Ptr a)
pooledMallocBytes Pool
pool Int
size = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Pool -> Int -> IO (Ptr a)
forall a. Pool -> Int -> IO (Ptr a)
F.pooledMallocBytes Pool
pool Int
size)
{-# INLINE pooledRealloc #-}
pooledRealloc :: (MonadIO m, Storable a) => Pool -> Ptr a -> m (Ptr a)
pooledRealloc :: Pool -> Ptr a -> m (Ptr a)
pooledRealloc Pool
pool Ptr a
ptr = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Pool -> Ptr a -> IO (Ptr a)
forall a. Storable a => Pool -> Ptr a -> IO (Ptr a)
F.pooledRealloc Pool
pool Ptr a
ptr)
{-# INLINE pooledReallocBytes #-}
pooledReallocBytes :: MonadIO m => Pool -> Ptr a -> Int -> m (Ptr a)
pooledReallocBytes :: Pool -> Ptr a -> Int -> m (Ptr a)
pooledReallocBytes Pool
pool Ptr a
ptr Int
size = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Pool -> Ptr a -> Int -> IO (Ptr a)
forall a. Pool -> Ptr a -> Int -> IO (Ptr a)
F.pooledReallocBytes Pool
pool Ptr a
ptr Int
size)
{-# INLINE pooledMallocArray #-}
pooledMallocArray :: (MonadIO m, Storable a) => Pool -> Int -> m (Ptr a)
pooledMallocArray :: Pool -> Int -> m (Ptr a)
pooledMallocArray Pool
pool Int
size = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Pool -> Int -> IO (Ptr a)
forall a. Storable a => Pool -> Int -> IO (Ptr a)
F.pooledMallocArray Pool
pool Int
size)
{-# INLINE pooledMallocArray0 #-}
pooledMallocArray0 :: (MonadIO m, Storable a) => Pool -> Int -> m (Ptr a)
pooledMallocArray0 :: Pool -> Int -> m (Ptr a)
pooledMallocArray0 Pool
pool Int
size = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Pool -> Int -> IO (Ptr a)
forall a. Storable a => Pool -> Int -> IO (Ptr a)
F.pooledMallocArray0 Pool
pool Int
size)
{-# INLINE pooledReallocArray #-}
pooledReallocArray ::
(MonadIO m, Storable a) => Pool -> Ptr a -> Int -> m (Ptr a)
pooledReallocArray :: Pool -> Ptr a -> Int -> m (Ptr a)
pooledReallocArray Pool
pool Ptr a
ptr Int
size = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Pool -> Ptr a -> Int -> IO (Ptr a)
forall a. Storable a => Pool -> Ptr a -> Int -> IO (Ptr a)
F.pooledReallocArray Pool
pool Ptr a
ptr Int
size)
{-# INLINE pooledReallocArray0 #-}
pooledReallocArray0 ::
(MonadIO m, Storable a) => Pool -> Ptr a -> Int -> m (Ptr a)
pooledReallocArray0 :: Pool -> Ptr a -> Int -> m (Ptr a)
pooledReallocArray0 Pool
pool Ptr a
ptr Int
size = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Pool -> Ptr a -> Int -> IO (Ptr a)
forall a. Storable a => Pool -> Ptr a -> Int -> IO (Ptr a)
F.pooledReallocArray0 Pool
pool Ptr a
ptr Int
size)
{-# INLINE pooledNew #-}
pooledNew :: (MonadIO m, Storable a) => Pool -> a -> m (Ptr a)
pooledNew :: Pool -> a -> m (Ptr a)
pooledNew Pool
pool a
val = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Pool -> a -> IO (Ptr a)
forall a. Storable a => Pool -> a -> IO (Ptr a)
F.pooledNew Pool
pool a
val)
{-# INLINE pooledNewArray #-}
pooledNewArray :: (MonadIO m, Storable a) => Pool -> [a] -> m (Ptr a)
pooledNewArray :: Pool -> [a] -> m (Ptr a)
pooledNewArray Pool
pool [a]
vals = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Pool -> [a] -> IO (Ptr a)
forall a. Storable a => Pool -> [a] -> IO (Ptr a)
F.pooledNewArray Pool
pool [a]
vals)
{-# INLINE pooledNewArray0 #-}
pooledNewArray0 :: (MonadIO m, Storable a) => Pool -> a -> [a] -> m (Ptr a)
pooledNewArray0 :: Pool -> a -> [a] -> m (Ptr a)
pooledNewArray0 Pool
pool a
marker [a]
vals = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Pool -> a -> [a] -> IO (Ptr a)
forall a. Storable a => Pool -> a -> [a] -> IO (Ptr a)
F.pooledNewArray0 Pool
pool a
marker [a]
vals)
{-# INLINE with #-}
with :: (MonadUnliftIO m, Storable a) => a -> (Ptr a -> m b) -> m b
with :: a -> (Ptr a -> m b) -> m b
with a
val Ptr a -> m b
f = ((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> a -> (Ptr a -> IO b) -> IO b
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
F.with a
val (m b -> IO b
forall a. m a -> IO a
u (m b -> IO b) -> (Ptr a -> m b) -> Ptr a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> m b
f))
{-# INLINE new #-}
new :: (MonadIO m, Storable a) => a -> m (Ptr a)
new :: a -> m (Ptr a)
new = IO (Ptr a) -> m (Ptr a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr a) -> m (Ptr a)) -> (a -> IO (Ptr a)) -> a -> m (Ptr a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> IO (Ptr a)
forall a. Storable a => a -> IO (Ptr a)
F.new
{-# INLINE maybeNew #-}
maybeNew :: MonadIO m => (a -> m (Ptr b)) -> Maybe a -> m (Ptr b)
maybeNew :: (a -> m (Ptr b)) -> Maybe a -> m (Ptr b)
maybeNew = m (Ptr b) -> (a -> m (Ptr b)) -> Maybe a -> m (Ptr b)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Ptr b -> m (Ptr b)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr b
forall a. Ptr a
nullPtr)
{-# INLINE maybeWith #-}
maybeWith ::
MonadIO m
=> (a -> (Ptr b -> m c) -> m c)
-> Maybe a
-> (Ptr b -> m c)
-> m c
maybeWith :: (a -> (Ptr b -> m c) -> m c) -> Maybe a -> (Ptr b -> m c) -> m c
maybeWith = ((Ptr b -> m c) -> m c)
-> (a -> (Ptr b -> m c) -> m c) -> Maybe a -> (Ptr b -> m c) -> m c
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((Ptr b -> m c) -> Ptr b -> m c
forall a b. (a -> b) -> a -> b
$ Ptr b
forall a. Ptr a
nullPtr)
{-# INLINE maybePeek #-}
maybePeek :: MonadUnliftIO m => (Ptr a -> m b) -> Ptr a -> m (Maybe b)
maybePeek :: (Ptr a -> m b) -> Ptr a -> m (Maybe b)
maybePeek Ptr a -> m b
peek_ Ptr a
ptr = ((forall a. m a -> IO a) -> IO (Maybe b)) -> m (Maybe b)
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
forall a b. (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
F.maybePeek (m b -> IO b
forall a. m a -> IO a
u (m b -> IO b) -> (Ptr a -> m b) -> Ptr a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> m b
peek_) Ptr a
ptr)
{-# INLINE copyBytes #-}
copyBytes :: MonadIO m => Ptr a -> Ptr a -> Int -> m ()
copyBytes :: Ptr a -> Ptr a -> Int -> m ()
copyBytes Ptr a
dest Ptr a
src Int
size = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Ptr a -> Ptr a -> Int -> IO ()
forall a. Ptr a -> Ptr a -> Int -> IO ()
F.copyBytes Ptr a
dest Ptr a
src Int
size)
{-# INLINE moveBytes #-}
moveBytes :: MonadIO m => Ptr a -> Ptr a -> Int -> m ()
moveBytes :: Ptr a -> Ptr a -> Int -> m ()
moveBytes Ptr a
dest Ptr a
src Int
size = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Ptr a -> Ptr a -> Int -> IO ()
forall a. Ptr a -> Ptr a -> Int -> IO ()
F.moveBytes Ptr a
dest Ptr a
src Int
size)
#if MIN_VERSION_base(4,8,0)
{-# INLINE fillBytes #-}
fillBytes :: MonadIO m => Ptr a -> Word8 -> Int -> m ()
fillBytes :: Ptr a -> Word8 -> Int -> m ()
fillBytes Ptr a
dest Word8
char Int
size = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Ptr a -> Word8 -> Int -> IO ()
forall a. Ptr a -> Word8 -> Int -> IO ()
F.fillBytes Ptr a
dest Word8
char Int
size)
#endif