{-# LINE 1 "src/Data/Number/Flint/Flint/FFI.hsc" #-}
module Data.Number.Flint.Flint.FFI (
flint_malloc
, flint_realloc
, flint_calloc
, flint_bits
, FRandState (..)
, CFRandState (..)
, newFRandState
, withFRandState
, flint_rand_alloc
, flint_rand_free
, flint_randinit
, flint_randclear
, flint_set_num_threads
, flint_get_num_threads
, flint_set_num_workers
, flint_reset_num_workers
) where
import Foreign.C.String
import Foreign.C.Types
import Foreign.ForeignPtr
import Foreign.Ptr ( Ptr, FunPtr, plusPtr )
import Foreign.Storable
import Foreign.Marshal ( free )
import Data.Number.Flint.Flint.Internal
foreign import ccall "flint.h flint_malloc"
flint_malloc :: Ptr CSize -> IO ()
foreign import ccall "flint.h flint_realloc"
flint_realloc :: Ptr () -> Ptr CSize -> IO ()
foreign import ccall "flint.h flint_calloc"
flint_calloc :: Ptr CSize -> Ptr CSize -> IO ()
flint_release :: CULong
flint_release :: CULong
flint_release = CULong
30000
{-# LINE 69 "src/Data/Number/Flint/Flint/FFI.hsc" #-}
flint_bits :: CULong
flint_bits :: CULong
flint_bits = CULong
64
{-# LINE 71 "src/Data/Number/Flint/Flint/FFI.hsc" #-}
flint_d_bits :: CULong
flint_d_bits :: CULong
flint_d_bits = CULong
53
{-# LINE 73 "src/Data/Number/Flint/Flint/FFI.hsc" #-}
data FRandState = FRandState {-# UNPACK #-} !(ForeignPtr CFRandState)
type CFRandState = CFlint FRandState
instance Storable CFRandState where
{-# INLINE sizeOf #-}
sizeOf :: CFRandState -> Int
sizeOf CFRandState
_ = (Int
56)
{-# LINE 82 "src/Data/Number/Flint/Flint/FFI.hsc" #-}
{-# INLINE alignment #-}
alignment :: CFRandState -> Int
alignment CFRandState
_ = Int
8
{-# LINE 84 "src/Data/Number/Flint/Flint/FFI.hsc" #-}
peek = error "CFRandState.peek: Not defined"
poke :: Ptr CFRandState -> CFRandState -> IO ()
poke = [Char] -> Ptr CFRandState -> CFRandState -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
"CFRandState.poke: Not defined"
newFRandState :: IO FRandState
newFRandState = do
ForeignPtr CFRandState
p <- IO (ForeignPtr CFRandState)
forall a. Storable a => IO (ForeignPtr a)
mallocForeignPtr
ForeignPtr CFRandState -> (Ptr CFRandState -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CFRandState
p Ptr CFRandState -> IO ()
flint_randinit
FinalizerPtr CFRandState -> ForeignPtr CFRandState -> IO ()
forall a. FinalizerPtr a -> ForeignPtr a -> IO ()
addForeignPtrFinalizer FinalizerPtr CFRandState
p_flint_randclear ForeignPtr CFRandState
p
FRandState -> IO FRandState
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (FRandState -> IO FRandState) -> FRandState -> IO FRandState
forall a b. (a -> b) -> a -> b
$ ForeignPtr CFRandState -> FRandState
FRandState ForeignPtr CFRandState
p
{-# INLINE withFRandState #-}
withFRandState :: FRandState -> (Ptr CFRandState -> IO a) -> IO (FRandState, a)
withFRandState (FRandState ForeignPtr CFRandState
p) Ptr CFRandState -> IO a
f = do
ForeignPtr CFRandState
-> (Ptr CFRandState -> IO (FRandState, a)) -> IO (FRandState, a)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CFRandState
p ((Ptr CFRandState -> IO (FRandState, a)) -> IO (FRandState, a))
-> (Ptr CFRandState -> IO (FRandState, a)) -> IO (FRandState, a)
forall a b. (a -> b) -> a -> b
$ \Ptr CFRandState
fp -> Ptr CFRandState -> IO a
f Ptr CFRandState
fp IO a -> (a -> IO (FRandState, a)) -> IO (FRandState, a)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (FRandState, a) -> IO (FRandState, a)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ((FRandState, a) -> IO (FRandState, a))
-> (a -> (FRandState, a)) -> a -> IO (FRandState, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ForeignPtr CFRandState -> FRandState
FRandState ForeignPtr CFRandState
p,)
foreign import ccall "flint.h flint_rand_alloc"
flint_rand_alloc :: IO (Ptr CFRandState)
foreign import ccall "flint.h flint_rand_free"
flint_rand_free :: Ptr CFRandState -> IO ()
foreign import ccall "flint.h flint_randinit"
flint_randinit :: Ptr CFRandState -> IO ()
foreign import ccall "flint.h flint_randclear"
flint_randclear :: Ptr CFRandState -> IO ()
foreign import ccall "flint.h &flint_randclear"
p_flint_randclear :: FunPtr (Ptr CFRandState -> IO ())
foreign import ccall "flint.h flint_set_num_threads"
flint_set_num_threads :: CInt -> IO ()
foreign import ccall "flint.h flint_get_num_threads"
flint_get_num_threads :: IO ()
foreign import ccall "flint.h flint_set_num_workers"
flint_set_num_workers :: CInt -> IO CInt
foreign import ccall "flint.h flint_reset_num_workers"
flint_reset_num_workers :: CInt -> IO ()