{-# LANGUAGE Unsafe #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_HADDOCK not-home #-}
module Foreign.ForeignPtr.Imp
(
ForeignPtr
, FinalizerPtr
, FinalizerEnvPtr
, newForeignPtr
, newForeignPtr_
, addForeignPtrFinalizer
, newForeignPtrEnv
, addForeignPtrFinalizerEnv
, withForeignPtr
, finalizeForeignPtr
, unsafeForeignPtrToPtr
, touchForeignPtr
, castForeignPtr
, plusForeignPtr
, mallocForeignPtr
, mallocForeignPtrBytes
, mallocForeignPtrArray
, mallocForeignPtrArray0
)
where
import Foreign.Ptr
import Foreign.Storable ( Storable(sizeOf) )
import GHC.Base
import GHC.Num
import GHC.ForeignPtr
newForeignPtr :: FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr :: forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr a
finalizer Ptr a
p
= do ForeignPtr a
fObj <- forall a. Ptr a -> IO (ForeignPtr a)
newForeignPtr_ Ptr a
p
forall a. FinalizerPtr a -> ForeignPtr a -> IO ()
addForeignPtrFinalizer FinalizerPtr a
finalizer ForeignPtr a
fObj
forall (m :: * -> *) a. Monad m => a -> m a
return ForeignPtr a
fObj
newForeignPtrEnv ::
FinalizerEnvPtr env a -> Ptr env -> Ptr a -> IO (ForeignPtr a)
newForeignPtrEnv :: forall env a.
FinalizerEnvPtr env a -> Ptr env -> Ptr a -> IO (ForeignPtr a)
newForeignPtrEnv FinalizerEnvPtr env a
finalizer Ptr env
env Ptr a
p
= do ForeignPtr a
fObj <- forall a. Ptr a -> IO (ForeignPtr a)
newForeignPtr_ Ptr a
p
forall env a.
FinalizerEnvPtr env a -> Ptr env -> ForeignPtr a -> IO ()
addForeignPtrFinalizerEnv FinalizerEnvPtr env a
finalizer Ptr env
env ForeignPtr a
fObj
forall (m :: * -> *) a. Monad m => a -> m a
return ForeignPtr a
fObj
mallocForeignPtrArray :: Storable a => Int -> IO (ForeignPtr a)
mallocForeignPtrArray :: forall a. Storable a => Int -> IO (ForeignPtr a)
mallocForeignPtrArray = forall b. Storable b => b -> Int -> IO (ForeignPtr b)
doMalloc forall a. HasCallStack => a
undefined
where
doMalloc :: Storable b => b -> Int -> IO (ForeignPtr b)
doMalloc :: forall b. Storable b => b -> Int -> IO (ForeignPtr b)
doMalloc b
dummy Int
size = forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes (Int
size forall a. Num a => a -> a -> a
* forall a. Storable a => a -> Int
sizeOf b
dummy)
mallocForeignPtrArray0 :: Storable a => Int -> IO (ForeignPtr a)
mallocForeignPtrArray0 :: forall a. Storable a => Int -> IO (ForeignPtr a)
mallocForeignPtrArray0 Int
size = forall a. Storable a => Int -> IO (ForeignPtr a)
mallocForeignPtrArray (Int
size forall a. Num a => a -> a -> a
+ Int
1)