Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

26 lines (19 sloc) 0.683 kB
-- | Helpers for the bindings
module Data.Internal where
import Control.Monad.ST (runST)
import Control.Monad.ST.Unsafe (unsafeIOToST)
import Foreign.ForeignPtr
import Foreign.Storable
import GHC.ForeignPtr ( mallocPlainForeignPtrBytes )
-- | Convert IO action to ST action and execute it
runIO :: IO a -> a
runIO io = runST $ unsafeIOToST io
{-# INLINE runIO #-}
-- | Allocate storage for N elements
mallocVector :: Storable a => Int -> IO (ForeignPtr a)
{-# INLINE mallocVector #-}
mallocVector
= doMalloc undefined
where
doMalloc :: Storable b => b -> Int -> IO (ForeignPtr b)
doMalloc dummy size = mallocPlainForeignPtrBytes (size * sizeOf dummy)
Jump to Line
Something went wrong with that request. Please try again.