{-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE CPP #-}
module Raaz.Core.Types.Pointer
(
LengthUnit(..)
, BYTES(..)
, atLeast, atLeastAligned, atMost
, Ptr
, sizeOf, alignment, alignedSizeOf
, movePtr, alignPtr, nextLocation
, peekAligned, pokeAligned
, Pointer(..), unsafeWithPointer, unsafeWithPointerCast
, AlignedPtr (..) , ptrAlignment, nextAlignedPtr
, allocaBuffer, allocaSecure
, wipeMemory
, memset
, memcpy
, hFillBuf
) where
import Control.Exception ( bracket_ )
import Data.Vector.Unboxed ( MVector(..), Vector, Unbox )
import Foreign.Marshal.Alloc
import Foreign.Ptr ( Ptr, castPtr )
import qualified Foreign.Ptr as FP
import Foreign.Storable ( Storable, peek, poke )
import qualified Foreign.Storable as FS
import GHC.TypeLits
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Generic.Mutable as GVM
import Raaz.Core.Prelude
import Raaz.Core.Types.Equality
import Raaz.Core.Types.Copying
class (Enum u, Monoid u) => LengthUnit u where
inBytes :: u -> BYTES Int
newtype BYTES a = BYTES a
deriving ( Int -> BYTES a -> ShowS
[BYTES a] -> ShowS
BYTES a -> String
(Int -> BYTES a -> ShowS)
-> (BYTES a -> String) -> ([BYTES a] -> ShowS) -> Show (BYTES a)
forall a. Show a => Int -> BYTES a -> ShowS
forall a. Show a => [BYTES a] -> ShowS
forall a. Show a => BYTES a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> BYTES a -> ShowS
showsPrec :: Int -> BYTES a -> ShowS
$cshow :: forall a. Show a => BYTES a -> String
show :: BYTES a -> String
$cshowList :: forall a. Show a => [BYTES a] -> ShowS
showList :: [BYTES a] -> ShowS
Show, BYTES a -> BYTES a -> Bool
(BYTES a -> BYTES a -> Bool)
-> (BYTES a -> BYTES a -> Bool) -> Eq (BYTES a)
forall a. Eq a => BYTES a -> BYTES a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => BYTES a -> BYTES a -> Bool
== :: BYTES a -> BYTES a -> Bool
$c/= :: forall a. Eq a => BYTES a -> BYTES a -> Bool
/= :: BYTES a -> BYTES a -> Bool
Eq, BYTES a -> BYTES a -> Result
(BYTES a -> BYTES a -> Result) -> Equality (BYTES a)
forall a. Equality a => BYTES a -> BYTES a -> Result
forall a. (a -> a -> Result) -> Equality a
$ceq :: forall a. Equality a => BYTES a -> BYTES a -> Result
eq :: BYTES a -> BYTES a -> Result
Equality, Eq (BYTES a)
Eq (BYTES a) =>
(BYTES a -> BYTES a -> Ordering)
-> (BYTES a -> BYTES a -> Bool)
-> (BYTES a -> BYTES a -> Bool)
-> (BYTES a -> BYTES a -> Bool)
-> (BYTES a -> BYTES a -> Bool)
-> (BYTES a -> BYTES a -> BYTES a)
-> (BYTES a -> BYTES a -> BYTES a)
-> Ord (BYTES a)
BYTES a -> BYTES a -> Bool
BYTES a -> BYTES a -> Ordering
BYTES a -> BYTES a -> BYTES a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (BYTES a)
forall a. Ord a => BYTES a -> BYTES a -> Bool
forall a. Ord a => BYTES a -> BYTES a -> Ordering
forall a. Ord a => BYTES a -> BYTES a -> BYTES a
$ccompare :: forall a. Ord a => BYTES a -> BYTES a -> Ordering
compare :: BYTES a -> BYTES a -> Ordering
$c< :: forall a. Ord a => BYTES a -> BYTES a -> Bool
< :: BYTES a -> BYTES a -> Bool
$c<= :: forall a. Ord a => BYTES a -> BYTES a -> Bool
<= :: BYTES a -> BYTES a -> Bool
$c> :: forall a. Ord a => BYTES a -> BYTES a -> Bool
> :: BYTES a -> BYTES a -> Bool
$c>= :: forall a. Ord a => BYTES a -> BYTES a -> Bool
>= :: BYTES a -> BYTES a -> Bool
$cmax :: forall a. Ord a => BYTES a -> BYTES a -> BYTES a
max :: BYTES a -> BYTES a -> BYTES a
$cmin :: forall a. Ord a => BYTES a -> BYTES a -> BYTES a
min :: BYTES a -> BYTES a -> BYTES a
Ord, Int -> BYTES a
BYTES a -> Int
BYTES a -> [BYTES a]
BYTES a -> BYTES a
BYTES a -> BYTES a -> [BYTES a]
BYTES a -> BYTES a -> BYTES a -> [BYTES a]
(BYTES a -> BYTES a)
-> (BYTES a -> BYTES a)
-> (Int -> BYTES a)
-> (BYTES a -> Int)
-> (BYTES a -> [BYTES a])
-> (BYTES a -> BYTES a -> [BYTES a])
-> (BYTES a -> BYTES a -> [BYTES a])
-> (BYTES a -> BYTES a -> BYTES a -> [BYTES a])
-> Enum (BYTES a)
forall a. Enum a => Int -> BYTES a
forall a. Enum a => BYTES a -> Int
forall a. Enum a => BYTES a -> [BYTES a]
forall a. Enum a => BYTES a -> BYTES a
forall a. Enum a => BYTES a -> BYTES a -> [BYTES a]
forall a. Enum a => BYTES a -> BYTES a -> BYTES a -> [BYTES a]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: forall a. Enum a => BYTES a -> BYTES a
succ :: BYTES a -> BYTES a
$cpred :: forall a. Enum a => BYTES a -> BYTES a
pred :: BYTES a -> BYTES a
$ctoEnum :: forall a. Enum a => Int -> BYTES a
toEnum :: Int -> BYTES a
$cfromEnum :: forall a. Enum a => BYTES a -> Int
fromEnum :: BYTES a -> Int
$cenumFrom :: forall a. Enum a => BYTES a -> [BYTES a]
enumFrom :: BYTES a -> [BYTES a]
$cenumFromThen :: forall a. Enum a => BYTES a -> BYTES a -> [BYTES a]
enumFromThen :: BYTES a -> BYTES a -> [BYTES a]
$cenumFromTo :: forall a. Enum a => BYTES a -> BYTES a -> [BYTES a]
enumFromTo :: BYTES a -> BYTES a -> [BYTES a]
$cenumFromThenTo :: forall a. Enum a => BYTES a -> BYTES a -> BYTES a -> [BYTES a]
enumFromThenTo :: BYTES a -> BYTES a -> BYTES a -> [BYTES a]
Enum, Enum (BYTES a)
Real (BYTES a)
(Real (BYTES a), Enum (BYTES a)) =>
(BYTES a -> BYTES a -> BYTES a)
-> (BYTES a -> BYTES a -> BYTES a)
-> (BYTES a -> BYTES a -> BYTES a)
-> (BYTES a -> BYTES a -> BYTES a)
-> (BYTES a -> BYTES a -> (BYTES a, BYTES a))
-> (BYTES a -> BYTES a -> (BYTES a, BYTES a))
-> (BYTES a -> Integer)
-> Integral (BYTES a)
BYTES a -> Integer
BYTES a -> BYTES a -> (BYTES a, BYTES a)
BYTES a -> BYTES a -> BYTES a
forall a. Integral a => Enum (BYTES a)
forall a. Integral a => Real (BYTES a)
forall a. Integral a => BYTES a -> Integer
forall a. Integral a => BYTES a -> BYTES a -> (BYTES a, BYTES a)
forall a. Integral a => BYTES a -> BYTES a -> BYTES a
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: forall a. Integral a => BYTES a -> BYTES a -> BYTES a
quot :: BYTES a -> BYTES a -> BYTES a
$crem :: forall a. Integral a => BYTES a -> BYTES a -> BYTES a
rem :: BYTES a -> BYTES a -> BYTES a
$cdiv :: forall a. Integral a => BYTES a -> BYTES a -> BYTES a
div :: BYTES a -> BYTES a -> BYTES a
$cmod :: forall a. Integral a => BYTES a -> BYTES a -> BYTES a
mod :: BYTES a -> BYTES a -> BYTES a
$cquotRem :: forall a. Integral a => BYTES a -> BYTES a -> (BYTES a, BYTES a)
quotRem :: BYTES a -> BYTES a -> (BYTES a, BYTES a)
$cdivMod :: forall a. Integral a => BYTES a -> BYTES a -> (BYTES a, BYTES a)
divMod :: BYTES a -> BYTES a -> (BYTES a, BYTES a)
$ctoInteger :: forall a. Integral a => BYTES a -> Integer
toInteger :: BYTES a -> Integer
Integral
, Num (BYTES a)
Ord (BYTES a)
(Num (BYTES a), Ord (BYTES a)) =>
(BYTES a -> Rational) -> Real (BYTES a)
BYTES a -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
forall a. Real a => Num (BYTES a)
forall a. Real a => Ord (BYTES a)
forall a. Real a => BYTES a -> Rational
$ctoRational :: forall a. Real a => BYTES a -> Rational
toRational :: BYTES a -> Rational
Real, Integer -> BYTES a
BYTES a -> BYTES a
BYTES a -> BYTES a -> BYTES a
(BYTES a -> BYTES a -> BYTES a)
-> (BYTES a -> BYTES a -> BYTES a)
-> (BYTES a -> BYTES a -> BYTES a)
-> (BYTES a -> BYTES a)
-> (BYTES a -> BYTES a)
-> (BYTES a -> BYTES a)
-> (Integer -> BYTES a)
-> Num (BYTES a)
forall a. Num a => Integer -> BYTES a
forall a. Num a => BYTES a -> BYTES a
forall a. Num a => BYTES a -> BYTES a -> BYTES a
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: forall a. Num a => BYTES a -> BYTES a -> BYTES a
+ :: BYTES a -> BYTES a -> BYTES a
$c- :: forall a. Num a => BYTES a -> BYTES a -> BYTES a
- :: BYTES a -> BYTES a -> BYTES a
$c* :: forall a. Num a => BYTES a -> BYTES a -> BYTES a
* :: BYTES a -> BYTES a -> BYTES a
$cnegate :: forall a. Num a => BYTES a -> BYTES a
negate :: BYTES a -> BYTES a
$cabs :: forall a. Num a => BYTES a -> BYTES a
abs :: BYTES a -> BYTES a
$csignum :: forall a. Num a => BYTES a -> BYTES a
signum :: BYTES a -> BYTES a
$cfromInteger :: forall a. Num a => Integer -> BYTES a
fromInteger :: Integer -> BYTES a
Num, Ptr (BYTES a) -> IO (BYTES a)
Ptr (BYTES a) -> Int -> IO (BYTES a)
Ptr (BYTES a) -> Int -> BYTES a -> IO ()
Ptr (BYTES a) -> BYTES a -> IO ()
BYTES a -> Int
(BYTES a -> Int)
-> (BYTES a -> Int)
-> (Ptr (BYTES a) -> Int -> IO (BYTES a))
-> (Ptr (BYTES a) -> Int -> BYTES a -> IO ())
-> (forall b. Ptr b -> Int -> IO (BYTES a))
-> (forall b. Ptr b -> Int -> BYTES a -> IO ())
-> (Ptr (BYTES a) -> IO (BYTES a))
-> (Ptr (BYTES a) -> BYTES a -> IO ())
-> Storable (BYTES a)
forall b. Ptr b -> Int -> IO (BYTES a)
forall b. Ptr b -> Int -> BYTES a -> IO ()
forall a. Storable a => Ptr (BYTES a) -> IO (BYTES a)
forall a. Storable a => Ptr (BYTES a) -> Int -> IO (BYTES a)
forall a. Storable a => Ptr (BYTES a) -> Int -> BYTES a -> IO ()
forall a. Storable a => Ptr (BYTES a) -> BYTES a -> IO ()
forall a. Storable a => BYTES a -> Int
forall a b. Storable a => Ptr b -> Int -> IO (BYTES a)
forall a b. Storable a => Ptr b -> Int -> BYTES a -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
$csizeOf :: forall a. Storable a => BYTES a -> Int
sizeOf :: BYTES a -> Int
$calignment :: forall a. Storable a => BYTES a -> Int
alignment :: BYTES a -> Int
$cpeekElemOff :: forall a. Storable a => Ptr (BYTES a) -> Int -> IO (BYTES a)
peekElemOff :: Ptr (BYTES a) -> Int -> IO (BYTES a)
$cpokeElemOff :: forall a. Storable a => Ptr (BYTES a) -> Int -> BYTES a -> IO ()
pokeElemOff :: Ptr (BYTES a) -> Int -> BYTES a -> IO ()
$cpeekByteOff :: forall a b. Storable a => Ptr b -> Int -> IO (BYTES a)
peekByteOff :: forall b. Ptr b -> Int -> IO (BYTES a)
$cpokeByteOff :: forall a b. Storable a => Ptr b -> Int -> BYTES a -> IO ()
pokeByteOff :: forall b. Ptr b -> Int -> BYTES a -> IO ()
$cpeek :: forall a. Storable a => Ptr (BYTES a) -> IO (BYTES a)
peek :: Ptr (BYTES a) -> IO (BYTES a)
$cpoke :: forall a. Storable a => Ptr (BYTES a) -> BYTES a -> IO ()
poke :: Ptr (BYTES a) -> BYTES a -> IO ()
Storable, BYTES a
BYTES a -> BYTES a -> Bounded (BYTES a)
forall a. a -> a -> Bounded a
forall a. Bounded a => BYTES a
$cminBound :: forall a. Bounded a => BYTES a
minBound :: BYTES a
$cmaxBound :: forall a. Bounded a => BYTES a
maxBound :: BYTES a
Bounded, Eq (BYTES a)
BYTES a
Eq (BYTES a) =>
(BYTES a -> BYTES a -> BYTES a)
-> (BYTES a -> BYTES a -> BYTES a)
-> (BYTES a -> BYTES a -> BYTES a)
-> (BYTES a -> BYTES a)
-> (BYTES a -> Int -> BYTES a)
-> (BYTES a -> Int -> BYTES a)
-> BYTES a
-> (Int -> BYTES a)
-> (BYTES a -> Int -> BYTES a)
-> (BYTES a -> Int -> BYTES a)
-> (BYTES a -> Int -> BYTES a)
-> (BYTES a -> Int -> Bool)
-> (BYTES a -> Maybe Int)
-> (BYTES a -> Int)
-> (BYTES a -> Bool)
-> (BYTES a -> Int -> BYTES a)
-> (BYTES a -> Int -> BYTES a)
-> (BYTES a -> Int -> BYTES a)
-> (BYTES a -> Int -> BYTES a)
-> (BYTES a -> Int -> BYTES a)
-> (BYTES a -> Int -> BYTES a)
-> (BYTES a -> Int)
-> Bits (BYTES a)
Int -> BYTES a
BYTES a -> Bool
BYTES a -> Int
BYTES a -> Maybe Int
BYTES a -> BYTES a
BYTES a -> Int -> Bool
BYTES a -> Int -> BYTES a
BYTES a -> BYTES a -> BYTES a
forall a.
Eq a =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
forall a. Bits a => Eq (BYTES a)
forall a. Bits a => BYTES a
forall a. Bits a => Int -> BYTES a
forall a. Bits a => BYTES a -> Bool
forall a. Bits a => BYTES a -> Int
forall a. Bits a => BYTES a -> Maybe Int
forall a. Bits a => BYTES a -> BYTES a
forall a. Bits a => BYTES a -> Int -> Bool
forall a. Bits a => BYTES a -> Int -> BYTES a
forall a. Bits a => BYTES a -> BYTES a -> BYTES a
$c.&. :: forall a. Bits a => BYTES a -> BYTES a -> BYTES a
.&. :: BYTES a -> BYTES a -> BYTES a
$c.|. :: forall a. Bits a => BYTES a -> BYTES a -> BYTES a
.|. :: BYTES a -> BYTES a -> BYTES a
$cxor :: forall a. Bits a => BYTES a -> BYTES a -> BYTES a
xor :: BYTES a -> BYTES a -> BYTES a
$ccomplement :: forall a. Bits a => BYTES a -> BYTES a
complement :: BYTES a -> BYTES a
$cshift :: forall a. Bits a => BYTES a -> Int -> BYTES a
shift :: BYTES a -> Int -> BYTES a
$crotate :: forall a. Bits a => BYTES a -> Int -> BYTES a
rotate :: BYTES a -> Int -> BYTES a
$czeroBits :: forall a. Bits a => BYTES a
zeroBits :: BYTES a
$cbit :: forall a. Bits a => Int -> BYTES a
bit :: Int -> BYTES a
$csetBit :: forall a. Bits a => BYTES a -> Int -> BYTES a
setBit :: BYTES a -> Int -> BYTES a
$cclearBit :: forall a. Bits a => BYTES a -> Int -> BYTES a
clearBit :: BYTES a -> Int -> BYTES a
$ccomplementBit :: forall a. Bits a => BYTES a -> Int -> BYTES a
complementBit :: BYTES a -> Int -> BYTES a
$ctestBit :: forall a. Bits a => BYTES a -> Int -> Bool
testBit :: BYTES a -> Int -> Bool
$cbitSizeMaybe :: forall a. Bits a => BYTES a -> Maybe Int
bitSizeMaybe :: BYTES a -> Maybe Int
$cbitSize :: forall a. Bits a => BYTES a -> Int
bitSize :: BYTES a -> Int
$cisSigned :: forall a. Bits a => BYTES a -> Bool
isSigned :: BYTES a -> Bool
$cshiftL :: forall a. Bits a => BYTES a -> Int -> BYTES a
shiftL :: BYTES a -> Int -> BYTES a
$cunsafeShiftL :: forall a. Bits a => BYTES a -> Int -> BYTES a
unsafeShiftL :: BYTES a -> Int -> BYTES a
$cshiftR :: forall a. Bits a => BYTES a -> Int -> BYTES a
shiftR :: BYTES a -> Int -> BYTES a
$cunsafeShiftR :: forall a. Bits a => BYTES a -> Int -> BYTES a
unsafeShiftR :: BYTES a -> Int -> BYTES a
$crotateL :: forall a. Bits a => BYTES a -> Int -> BYTES a
rotateL :: BYTES a -> Int -> BYTES a
$crotateR :: forall a. Bits a => BYTES a -> Int -> BYTES a
rotateR :: BYTES a -> Int -> BYTES a
$cpopCount :: forall a. Bits a => BYTES a -> Int
popCount :: BYTES a -> Int
Bits
)
instance Functor BYTES where
fmap :: forall a b. (a -> b) -> BYTES a -> BYTES b
fmap a -> b
f (BYTES a
x) = b -> BYTES b
forall a. a -> BYTES a
BYTES (a -> b
f a
x)
instance Num a => Semigroup (BYTES a) where
<> :: BYTES a -> BYTES a -> BYTES a
(<>) = BYTES a -> BYTES a -> BYTES a
forall a. Num a => a -> a -> a
(+)
instance Num a => Monoid (BYTES a) where
mempty :: BYTES a
mempty = BYTES a
0
mappend :: BYTES a -> BYTES a -> BYTES a
mappend = BYTES a -> BYTES a -> BYTES a
forall a. Semigroup a => a -> a -> a
(<>)
newtype Alignment = Alignment { Alignment -> Int
unAlignment :: Int }
deriving ( Int -> Alignment -> ShowS
[Alignment] -> ShowS
Alignment -> String
(Int -> Alignment -> ShowS)
-> (Alignment -> String)
-> ([Alignment] -> ShowS)
-> Show Alignment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Alignment -> ShowS
showsPrec :: Int -> Alignment -> ShowS
$cshow :: Alignment -> String
show :: Alignment -> String
$cshowList :: [Alignment] -> ShowS
showList :: [Alignment] -> ShowS
Show, Alignment -> Alignment -> Bool
(Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool) -> Eq Alignment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Alignment -> Alignment -> Bool
== :: Alignment -> Alignment -> Bool
$c/= :: Alignment -> Alignment -> Bool
/= :: Alignment -> Alignment -> Bool
Eq, Eq Alignment
Eq Alignment =>
(Alignment -> Alignment -> Ordering)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> Ord Alignment
Alignment -> Alignment -> Bool
Alignment -> Alignment -> Ordering
Alignment -> Alignment -> Alignment
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Alignment -> Alignment -> Ordering
compare :: Alignment -> Alignment -> Ordering
$c< :: Alignment -> Alignment -> Bool
< :: Alignment -> Alignment -> Bool
$c<= :: Alignment -> Alignment -> Bool
<= :: Alignment -> Alignment -> Bool
$c> :: Alignment -> Alignment -> Bool
> :: Alignment -> Alignment -> Bool
$c>= :: Alignment -> Alignment -> Bool
>= :: Alignment -> Alignment -> Bool
$cmax :: Alignment -> Alignment -> Alignment
max :: Alignment -> Alignment -> Alignment
$cmin :: Alignment -> Alignment -> Alignment
min :: Alignment -> Alignment -> Alignment
Ord, Int -> Alignment
Alignment -> Int
Alignment -> [Alignment]
Alignment -> Alignment
Alignment -> Alignment -> [Alignment]
Alignment -> Alignment -> Alignment -> [Alignment]
(Alignment -> Alignment)
-> (Alignment -> Alignment)
-> (Int -> Alignment)
-> (Alignment -> Int)
-> (Alignment -> [Alignment])
-> (Alignment -> Alignment -> [Alignment])
-> (Alignment -> Alignment -> [Alignment])
-> (Alignment -> Alignment -> Alignment -> [Alignment])
-> Enum Alignment
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Alignment -> Alignment
succ :: Alignment -> Alignment
$cpred :: Alignment -> Alignment
pred :: Alignment -> Alignment
$ctoEnum :: Int -> Alignment
toEnum :: Int -> Alignment
$cfromEnum :: Alignment -> Int
fromEnum :: Alignment -> Int
$cenumFrom :: Alignment -> [Alignment]
enumFrom :: Alignment -> [Alignment]
$cenumFromThen :: Alignment -> Alignment -> [Alignment]
enumFromThen :: Alignment -> Alignment -> [Alignment]
$cenumFromTo :: Alignment -> Alignment -> [Alignment]
enumFromTo :: Alignment -> Alignment -> [Alignment]
$cenumFromThenTo :: Alignment -> Alignment -> Alignment -> [Alignment]
enumFromThenTo :: Alignment -> Alignment -> Alignment -> [Alignment]
Enum)
instance Semigroup Alignment where
<> :: Alignment -> Alignment -> Alignment
(<>) Alignment
a Alignment
b = Int -> Alignment
Alignment (Int -> Alignment) -> Int -> Alignment
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Integral a => a -> a -> a
lcm (Alignment -> Int
unAlignment Alignment
a) (Alignment -> Int
unAlignment Alignment
b)
instance Monoid Alignment where
mempty :: Alignment
mempty = Int -> Alignment
Alignment Int
1
mappend :: Alignment -> Alignment -> Alignment
mappend = Alignment -> Alignment -> Alignment
forall a. Semigroup a => a -> a -> a
(<>)
sizeOf :: Storable a => Proxy a -> BYTES Int
sizeOf :: forall a. Storable a => Proxy a -> BYTES Int
sizeOf = Int -> BYTES Int
forall a. a -> BYTES a
BYTES (Int -> BYTES Int) -> (Proxy a -> Int) -> Proxy a -> BYTES Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Int
forall a. Storable a => a -> Int
FS.sizeOf (a -> Int) -> (Proxy a -> a) -> Proxy a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Proxy a -> a
forall a (proxy :: * -> *). a -> proxy a -> a
asProxyTypeOf a
forall a. HasCallStack => a
undefined
alignment :: Storable a => Proxy a -> Alignment
alignment :: forall a. Storable a => Proxy a -> Alignment
alignment = Int -> Alignment
Alignment (Int -> Alignment) -> (Proxy a -> Int) -> Proxy a -> Alignment
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Int
forall a. Storable a => a -> Int
FS.alignment (a -> Int) -> (Proxy a -> a) -> Proxy a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Proxy a -> a
forall a (proxy :: * -> *). a -> proxy a -> a
asProxyTypeOf a
forall a. HasCallStack => a
undefined
movePtr :: LengthUnit l => Ptr a -> l -> Ptr a
movePtr :: forall l a. LengthUnit l => Ptr a -> l -> Ptr a
movePtr Ptr a
ptr l
l = Ptr a -> Int -> Ptr a
forall a b. Ptr a -> Int -> Ptr b
FP.plusPtr Ptr a
ptr Int
offset
where BYTES Int
offset = l -> BYTES Int
forall u. LengthUnit u => u -> BYTES Int
inBytes l
l
alignPtr :: Storable a => Ptr a -> Alignment -> Ptr a
alignPtr :: forall a. Storable a => Ptr a -> Alignment -> Ptr a
alignPtr Ptr a
ptr = Ptr a -> Int -> Ptr a
forall a. Ptr a -> Int -> Ptr a
FP.alignPtr Ptr a
ptr (Int -> Ptr a) -> (Alignment -> Int) -> Alignment -> Ptr a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Alignment -> Int
unAlignment
alignedSizeOf :: Storable a => Proxy a -> BYTES Int
alignedSizeOf :: forall a. Storable a => Proxy a -> BYTES Int
alignedSizeOf Proxy a
aproxy = BYTES Int -> Alignment -> BYTES Int
forall l. LengthUnit l => l -> Alignment -> BYTES Int
atLeastAligned (Proxy a -> BYTES Int
forall a. Storable a => Proxy a -> BYTES Int
sizeOf Proxy a
aproxy) (Alignment -> BYTES Int) -> Alignment -> BYTES Int
forall a b. (a -> b) -> a -> b
$ Proxy a -> Alignment
forall a. Storable a => Proxy a -> Alignment
alignment Proxy a
aproxy
nextLocation :: Storable a => Ptr a -> Ptr a
nextLocation :: forall a. Storable a => Ptr a -> Ptr a
nextLocation Ptr a
ptr = Ptr a -> Alignment -> Ptr a
forall a. Storable a => Ptr a -> Alignment -> Ptr a
alignPtr Ptr a
ptr (Alignment -> Ptr a) -> Alignment -> Ptr a
forall a b. (a -> b) -> a -> b
$ Proxy a -> Alignment
forall a. Storable a => Proxy a -> Alignment
alignment (Proxy a -> Alignment) -> Proxy a -> Alignment
forall a b. (a -> b) -> a -> b
$ Ptr a -> Proxy a
forall b. Ptr b -> Proxy b
getProxy Ptr a
ptr
where getProxy :: Ptr b -> Proxy b
getProxy :: forall b. Ptr b -> Proxy b
getProxy = Proxy b -> Ptr b -> Proxy b
forall a b. a -> b -> a
const Proxy b
forall {k} (t :: k). Proxy t
Proxy
peekAligned :: Storable a => Ptr a -> IO a
peekAligned :: forall a. Storable a => Ptr a -> IO a
peekAligned = Ptr a -> IO a
forall a. Storable a => Ptr a -> IO a
peek (Ptr a -> IO a) -> (Ptr a -> Ptr a) -> Ptr a -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> Ptr a
forall a. Storable a => Ptr a -> Ptr a
nextLocation
pokeAligned :: Storable a => Ptr a -> a -> IO ()
pokeAligned :: forall a. Storable a => Ptr a -> a -> IO ()
pokeAligned Ptr a
ptr = Ptr a -> a -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr a -> a -> IO ()) -> Ptr a -> a -> IO ()
forall a b. (a -> b) -> a -> b
$ Ptr a -> Ptr a
forall a. Storable a => Ptr a -> Ptr a
nextLocation Ptr a
ptr
instance LengthUnit (BYTES Int) where
inBytes :: BYTES Int -> BYTES Int
inBytes = BYTES Int -> BYTES Int
forall a. a -> a
id
{-# INLINE inBytes #-}
atLeast :: ( LengthUnit src
, LengthUnit dest
)
=> src
-> dest
atLeast :: forall src dest. (LengthUnit src, LengthUnit dest) => src -> dest
atLeast src
src | BYTES Int
r BYTES Int -> BYTES Int -> Bool
forall a. Eq a => a -> a -> Bool
== BYTES Int
0 = dest
u
| Bool
otherwise = dest -> dest
forall a. Enum a => a -> a
succ dest
u
where (dest
u , BYTES Int
r) = BYTES Int -> (dest, BYTES Int)
forall u. LengthUnit u => BYTES Int -> (u, BYTES Int)
bytesQuotRem (BYTES Int -> (dest, BYTES Int)) -> BYTES Int -> (dest, BYTES Int)
forall a b. (a -> b) -> a -> b
$ src -> BYTES Int
forall u. LengthUnit u => u -> BYTES Int
inBytes src
src
atLeastAligned :: LengthUnit l => l -> Alignment -> BYTES Int
atLeastAligned :: forall l. LengthUnit l => l -> Alignment -> BYTES Int
atLeastAligned l
l Alignment
a = BYTES Int
n BYTES Int -> BYTES Int -> BYTES Int
forall a. Semigroup a => a -> a -> a
<> BYTES Int
pad
where n :: BYTES Int
n = l -> BYTES Int
forall src dest. (LengthUnit src, LengthUnit dest) => src -> dest
atLeast l
l
pad :: BYTES Int
pad = Int -> BYTES Int
forall a. a -> BYTES a
BYTES (Int -> BYTES Int) -> Int -> BYTES Int
forall a b. (a -> b) -> a -> b
$ Alignment -> Int
unAlignment Alignment
a
atMost :: ( LengthUnit src
, LengthUnit dest
)
=> src
-> dest
atMost :: forall src dest. (LengthUnit src, LengthUnit dest) => src -> dest
atMost = (dest, BYTES Int) -> dest
forall a b. (a, b) -> a
fst ((dest, BYTES Int) -> dest)
-> (src -> (dest, BYTES Int)) -> src -> dest
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BYTES Int -> (dest, BYTES Int)
forall u. LengthUnit u => BYTES Int -> (u, BYTES Int)
bytesQuotRem (BYTES Int -> (dest, BYTES Int))
-> (src -> BYTES Int) -> src -> (dest, BYTES Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. src -> BYTES Int
forall u. LengthUnit u => u -> BYTES Int
inBytes
bytesQuotRem :: LengthUnit u
=> BYTES Int
-> (u , BYTES Int)
bytesQuotRem :: forall u. LengthUnit u => BYTES Int -> (u, BYTES Int)
bytesQuotRem BYTES Int
bytes = (u
u , BYTES Int
r)
where divisor :: BYTES Int
divisor = u -> BYTES Int
forall u. LengthUnit u => u -> BYTES Int
inBytes (Int -> u
forall a. Enum a => Int -> a
toEnum Int
1 u -> u -> u
forall a. a -> a -> a
`asTypeOf` u
u)
(BYTES Int
q, BYTES Int
r) = BYTES Int
bytes BYTES Int -> BYTES Int -> (BYTES Int, BYTES Int)
forall a. Integral a => a -> a -> (a, a)
`quotRem` BYTES Int
divisor
u :: u
u = Int -> u
forall a. Enum a => Int -> a
toEnum Int
q
class Pointer (ptr :: Type -> Type) where
castPointer :: ptr a -> ptr b
allocaPointer :: BYTES Int
-> (ptr a -> IO b)
-> IO b
unsafeRawPtr :: ptr a -> Ptr a
instance Pointer Ptr where
unsafeRawPtr :: forall a. Ptr a -> Ptr a
unsafeRawPtr = Ptr a -> Ptr a
forall a. a -> a
id
{-# INLINE unsafeRawPtr #-}
castPointer :: forall a b. Ptr a -> Ptr b
castPointer = Ptr a -> Ptr b
forall a b. Ptr a -> Ptr b
castPtr
{-# INLINE castPointer #-}
allocaPointer :: forall a b. BYTES Int -> (Ptr a -> IO b) -> IO b
allocaPointer (BYTES Int
sz) = Int -> (Ptr a -> IO b) -> IO b
forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes Int
sz
unsafeWithPointer :: Pointer ptr => (Ptr a -> b) -> ptr a -> b
unsafeWithPointer :: forall (ptr :: * -> *) a b.
Pointer ptr =>
(Ptr a -> b) -> ptr a -> b
unsafeWithPointer Ptr a -> b
action = Ptr a -> b
action (Ptr a -> b) -> (ptr a -> Ptr a) -> ptr a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ptr a -> Ptr a
forall a. ptr a -> Ptr a
forall (ptr :: * -> *) a. Pointer ptr => ptr a -> Ptr a
unsafeRawPtr
unsafeWithPointerCast :: Pointer ptr => (Ptr a -> b) -> ptr something -> b
unsafeWithPointerCast :: forall (ptr :: * -> *) a b something.
Pointer ptr =>
(Ptr a -> b) -> ptr something -> b
unsafeWithPointerCast Ptr a -> b
action = (Ptr a -> b) -> ptr a -> b
forall (ptr :: * -> *) a b.
Pointer ptr =>
(Ptr a -> b) -> ptr a -> b
unsafeWithPointer Ptr a -> b
action (ptr a -> b) -> (ptr something -> ptr a) -> ptr something -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ptr something -> ptr a
forall a b. ptr a -> ptr b
forall (ptr :: * -> *) a b. Pointer ptr => ptr a -> ptr b
castPointer
allocaBuffer :: ( LengthUnit l, Pointer ptr)
=> l
-> (ptr something -> IO b)
-> IO b
allocaBuffer :: forall l (ptr :: * -> *) something b.
(LengthUnit l, Pointer ptr) =>
l -> (ptr something -> IO b) -> IO b
allocaBuffer = BYTES Int -> (ptr something -> IO b) -> IO b
forall a b. BYTES Int -> (ptr a -> IO b) -> IO b
forall (ptr :: * -> *) a b.
Pointer ptr =>
BYTES Int -> (ptr a -> IO b) -> IO b
allocaPointer (BYTES Int -> (ptr something -> IO b) -> IO b)
-> (l -> BYTES Int) -> l -> (ptr something -> IO b) -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l -> BYTES Int
forall u. LengthUnit u => u -> BYTES Int
inBytes
allocaSecure :: ( LengthUnit l, Pointer ptr)
=> l
-> (ptr a -> IO b)
-> IO b
allocaSecure :: forall l (ptr :: * -> *) something b.
(LengthUnit l, Pointer ptr) =>
l -> (ptr something -> IO b) -> IO b
allocaSecure l
l ptr a -> IO b
action = l -> (ptr a -> IO b) -> IO b
forall l (ptr :: * -> *) something b.
(LengthUnit l, Pointer ptr) =>
l -> (ptr something -> IO b) -> IO b
allocaBuffer l
l ptr a -> IO b
actual
where actual :: ptr a -> IO b
actual ptr a
ptr = IO () -> IO () -> IO b -> IO b
forall a b c. IO a -> IO b -> IO c -> IO c
bracket_ (ptr a -> IO ()
lockIt ptr a
ptr) (ptr a -> IO ()
releaseIt ptr a
ptr) (IO b -> IO b) -> IO b -> IO b
forall a b. (a -> b) -> a -> b
$ ptr a -> IO b
action ptr a
ptr
lockIt :: ptr a -> IO ()
lockIt ptr a
ptr = do Int
c <- ptr a -> l -> IO Int
forall l (ptr :: * -> *) a.
(LengthUnit l, Pointer ptr) =>
ptr a -> l -> IO Int
memlock ptr a
ptr l
l
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
c Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> IO ()
forall a. String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"secure memory: unable to lock memory"
releaseIt :: ptr a -> IO ()
releaseIt ptr a
ptr = ptr a -> l -> IO ()
forall l (ptr :: * -> *) a.
(LengthUnit l, Pointer ptr) =>
ptr a -> l -> IO ()
wipeMemory ptr a
ptr l
l IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ptr a -> l -> IO ()
forall l (ptr :: * -> *) a.
(LengthUnit l, Pointer ptr) =>
ptr a -> l -> IO ()
memunlock ptr a
ptr l
l
foreign import ccall unsafe "raaz/core/memory.h raazMemorylock"
c_mlock :: Ptr a -> BYTES Int -> IO Int
foreign import ccall unsafe "raaz/core/memory.h raazMemoryunlock"
c_munlock :: Ptr a -> BYTES Int -> IO ()
foreign import ccall unsafe "raazWipeMemory" c_wipe_memory
:: Ptr a -> BYTES Int -> IO ()
memlock :: (LengthUnit l, Pointer ptr)
=> ptr a
-> l
-> IO Int
memlock :: forall l (ptr :: * -> *) a.
(LengthUnit l, Pointer ptr) =>
ptr a -> l -> IO Int
memlock ptr a
ptr = (Ptr a -> BYTES Int -> IO Int) -> ptr a -> BYTES Int -> IO Int
forall (ptr :: * -> *) a b.
Pointer ptr =>
(Ptr a -> b) -> ptr a -> b
unsafeWithPointer Ptr a -> BYTES Int -> IO Int
forall a. Ptr a -> BYTES Int -> IO Int
c_mlock ptr a
ptr (BYTES Int -> IO Int) -> (l -> BYTES Int) -> l -> IO Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l -> BYTES Int
forall u. LengthUnit u => u -> BYTES Int
inBytes
memunlock :: (LengthUnit l, Pointer ptr)
=> ptr a
-> l
-> IO ()
memunlock :: forall l (ptr :: * -> *) a.
(LengthUnit l, Pointer ptr) =>
ptr a -> l -> IO ()
memunlock ptr a
ptr = (Ptr a -> BYTES Int -> IO ()) -> ptr a -> BYTES Int -> IO ()
forall (ptr :: * -> *) a b.
Pointer ptr =>
(Ptr a -> b) -> ptr a -> b
unsafeWithPointer Ptr a -> BYTES Int -> IO ()
forall a. Ptr a -> BYTES Int -> IO ()
c_munlock ptr a
ptr (BYTES Int -> IO ()) -> (l -> BYTES Int) -> l -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l -> BYTES Int
forall u. LengthUnit u => u -> BYTES Int
inBytes
wipeMemory :: (LengthUnit l, Pointer ptr)
=> ptr a
-> l
-> IO ()
wipeMemory :: forall l (ptr :: * -> *) a.
(LengthUnit l, Pointer ptr) =>
ptr a -> l -> IO ()
wipeMemory ptr a
p = IO () -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO () -> IO ()) -> (l -> IO ()) -> l -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Ptr a -> BYTES Int -> IO ()) -> ptr a -> BYTES Int -> IO ()
forall (ptr :: * -> *) a b.
Pointer ptr =>
(Ptr a -> b) -> ptr a -> b
unsafeWithPointer Ptr a -> BYTES Int -> IO ()
forall a. Ptr a -> BYTES Int -> IO ()
c_wipe_memory ptr a
p (BYTES Int -> IO ()) -> (l -> BYTES Int) -> l -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l -> BYTES Int
forall u. LengthUnit u => u -> BYTES Int
inBytes
{-# SPECIALIZE memlock :: Ptr a -> BYTES Int -> IO Int #-}
{-# SPECIALIZE memunlock :: Ptr a -> BYTES Int -> IO () #-}
{-# SPECIALISE wipeMemory :: Ptr a -> BYTES Int -> IO () #-}
hFillBuf :: (LengthUnit bufSize, Pointer ptr)
=> Handle
-> ptr a
-> bufSize
-> IO (BYTES Int)
{-# INLINE hFillBuf #-}
hFillBuf :: forall bufSize (ptr :: * -> *) a.
(LengthUnit bufSize, Pointer ptr) =>
Handle -> ptr a -> bufSize -> IO (BYTES Int)
hFillBuf Handle
handle ptr a
ptr bufSize
bufSize = Int -> BYTES Int
forall a. a -> BYTES a
BYTES (Int -> BYTES Int) -> IO Int -> IO (BYTES Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Handle -> Ptr a -> Int -> IO Int
forall a. Handle -> Ptr a -> Int -> IO Int
hGetBuf Handle
handle (ptr a -> Ptr a
forall a. ptr a -> Ptr a
forall (ptr :: * -> *) a. Pointer ptr => ptr a -> Ptr a
unsafeRawPtr ptr a
ptr) Int
bytes
where BYTES Int
bytes = bufSize -> BYTES Int
forall u. LengthUnit u => u -> BYTES Int
inBytes bufSize
bufSize
foreign import ccall unsafe "string.h memcpy" c_memcpy
:: Dest (Ptr dest) -> Src (Ptr src) -> BYTES Int -> IO (Ptr ())
memcpy :: (LengthUnit l, Pointer ptrS, Pointer ptrD)
=> Dest (ptrD dest)
-> Src (ptrS src)
-> l
-> IO ()
memcpy :: forall l (ptrS :: * -> *) (ptrD :: * -> *) dest src.
(LengthUnit l, Pointer ptrS, Pointer ptrD) =>
Dest (ptrD dest) -> Src (ptrS src) -> l -> IO ()
memcpy Dest (ptrD dest)
dest Src (ptrS src)
src = IO (Ptr ()) -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO (Ptr ()) -> IO ()) -> (l -> IO (Ptr ())) -> l -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dest (Ptr dest) -> Src (Ptr src) -> BYTES Int -> IO (Ptr ())
forall dest src.
Dest (Ptr dest) -> Src (Ptr src) -> BYTES Int -> IO (Ptr ())
c_memcpy Dest (Ptr dest)
destRaw Src (Ptr src)
srcRaw (BYTES Int -> IO (Ptr ())) -> (l -> BYTES Int) -> l -> IO (Ptr ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l -> BYTES Int
forall u. LengthUnit u => u -> BYTES Int
inBytes
where destRaw :: Dest (Ptr dest)
destRaw = ptrD dest -> Ptr dest
forall a. ptrD a -> Ptr a
forall (ptr :: * -> *) a. Pointer ptr => ptr a -> Ptr a
unsafeRawPtr (ptrD dest -> Ptr dest) -> Dest (ptrD dest) -> Dest (Ptr dest)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dest (ptrD dest)
dest
srcRaw :: Src (Ptr src)
srcRaw = ptrS src -> Ptr src
forall a. ptrS a -> Ptr a
forall (ptr :: * -> *) a. Pointer ptr => ptr a -> Ptr a
unsafeRawPtr (ptrS src -> Ptr src) -> Src (ptrS src) -> Src (Ptr src)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Src (ptrS src)
src
{-# SPECIALIZE memcpy :: Dest (Ptr dest) -> Src (Ptr src) -> BYTES Int -> IO () #-}
foreign import ccall unsafe "string.h memset" c_memset
:: Ptr buf -> Word8 -> BYTES Int -> IO (Ptr ())
memset :: (LengthUnit l, Pointer ptr)
=> ptr a
-> Word8
-> l
-> IO ()
memset :: forall l (ptr :: * -> *) a.
(LengthUnit l, Pointer ptr) =>
ptr a -> Word8 -> l -> IO ()
memset ptr a
p Word8
w = IO (Ptr ()) -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO (Ptr ()) -> IO ()) -> (l -> IO (Ptr ())) -> l -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Ptr a -> Word8 -> BYTES Int -> IO (Ptr ()))
-> ptr a -> Word8 -> BYTES Int -> IO (Ptr ())
forall (ptr :: * -> *) a b.
Pointer ptr =>
(Ptr a -> b) -> ptr a -> b
unsafeWithPointer Ptr a -> Word8 -> BYTES Int -> IO (Ptr ())
forall buf. Ptr buf -> Word8 -> BYTES Int -> IO (Ptr ())
c_memset ptr a
p Word8
w (BYTES Int -> IO (Ptr ())) -> (l -> BYTES Int) -> l -> IO (Ptr ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l -> BYTES Int
forall u. LengthUnit u => u -> BYTES Int
inBytes
{-# SPECIALIZE memset :: Ptr a -> Word8 -> BYTES Int -> IO () #-}
newtype AlignedPtr (n :: Nat) a = AlignedPtr { forall (n :: Nat) a. AlignedPtr n a -> Ptr a
forgetAlignment :: Ptr a}
instance KnownNat n => Pointer (AlignedPtr n) where
unsafeRawPtr :: forall a. AlignedPtr n a -> Ptr a
unsafeRawPtr = AlignedPtr n a -> Ptr a
forall (n :: Nat) a. AlignedPtr n a -> Ptr a
forgetAlignment
{-# INLINE unsafeRawPtr #-}
castPointer :: forall a b. AlignedPtr n a -> AlignedPtr n b
castPointer = Ptr b -> AlignedPtr n b
forall (n :: Nat) a. Ptr a -> AlignedPtr n a
AlignedPtr (Ptr b -> AlignedPtr n b)
-> (AlignedPtr n a -> Ptr b) -> AlignedPtr n a -> AlignedPtr n b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> Ptr b
forall a b. Ptr a -> Ptr b
castPtr (Ptr a -> Ptr b)
-> (AlignedPtr n a -> Ptr a) -> AlignedPtr n a -> Ptr b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AlignedPtr n a -> Ptr a
forall (n :: Nat) a. AlignedPtr n a -> Ptr a
forgetAlignment
{-# INLINE castPointer #-}
allocaPointer :: forall a b. BYTES Int -> (AlignedPtr n a -> IO b) -> IO b
allocaPointer (BYTES Int
sz) AlignedPtr n a -> IO b
action =
Int -> Int -> (Ptr a -> IO b) -> IO b
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned Int
sz Int
algn (AlignedPtr n a -> IO b
action (AlignedPtr n a -> IO b)
-> (Ptr a -> AlignedPtr n a) -> Ptr a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr a -> AlignedPtr n a
forall (n :: Nat) a. Ptr a -> AlignedPtr n a
AlignedPtr)
where algn :: Int
algn = Integer -> Int
forall a. Enum a => a -> Int
fromEnum (Integer -> Int) -> Integer -> Int
forall a b. (a -> b) -> a -> b
$ Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n -> Integer) -> Proxy n -> Integer
forall a b. (a -> b) -> a -> b
$ (AlignedPtr n a -> IO b) -> Proxy n
forall (n :: Nat) a b. (AlignedPtr n a -> IO b) -> Proxy n
getProxy AlignedPtr n a -> IO b
action
getProxy :: (AlignedPtr n a -> IO b) -> Proxy n
getProxy :: forall (n :: Nat) a b. (AlignedPtr n a -> IO b) -> Proxy n
getProxy AlignedPtr n a -> IO b
_ = Proxy n
forall {k} (t :: k). Proxy t
Proxy
nextAlignedPtr :: (Storable a, KnownNat n) => Ptr a -> AlignedPtr n a
nextAlignedPtr :: forall a (n :: Nat).
(Storable a, KnownNat n) =>
Ptr a -> AlignedPtr n a
nextAlignedPtr = Ptr a -> AlignedPtr n a
forall a (n :: Nat).
(Storable a, KnownNat n) =>
Ptr a -> AlignedPtr n a
alignIt
where alignIt :: Ptr a -> AlignedPtr n a
alignIt Ptr a
ptr = Ptr a -> AlignedPtr n a
forall (n :: Nat) a. Ptr a -> AlignedPtr n a
AlignedPtr
(Ptr a -> AlignedPtr n a) -> Ptr a -> AlignedPtr n a
forall a b. (a -> b) -> a -> b
$ Ptr a -> Alignment -> Ptr a
forall a. Storable a => Ptr a -> Alignment -> Ptr a
alignPtr Ptr a
ptr
(Alignment -> Ptr a) -> Alignment -> Ptr a
forall a b. (a -> b) -> a -> b
$ Proxy (AlignedPtr n a) -> Alignment
forall (n :: Nat) a.
KnownNat n =>
Proxy (AlignedPtr n a) -> Alignment
ptrAlignment
(Proxy (AlignedPtr n a) -> Alignment)
-> Proxy (AlignedPtr n a) -> Alignment
forall a b. (a -> b) -> a -> b
$ (Ptr a -> AlignedPtr n a) -> Proxy (AlignedPtr n a)
forall a (n :: Nat).
(Ptr a -> AlignedPtr n a) -> Proxy (AlignedPtr n a)
getProxy Ptr a -> AlignedPtr n a
alignIt
getProxy :: (Ptr a -> AlignedPtr n a) -> Proxy (AlignedPtr n a)
getProxy :: forall a (n :: Nat).
(Ptr a -> AlignedPtr n a) -> Proxy (AlignedPtr n a)
getProxy Ptr a -> AlignedPtr n a
_ = Proxy (AlignedPtr n a)
forall {k} (t :: k). Proxy t
Proxy
ptrAlignment :: KnownNat n => Proxy (AlignedPtr n a) -> Alignment
ptrAlignment :: forall (n :: Nat) a.
KnownNat n =>
Proxy (AlignedPtr n a) -> Alignment
ptrAlignment = Int -> Alignment
Alignment (Int -> Alignment)
-> (Proxy (AlignedPtr n a) -> Int)
-> Proxy (AlignedPtr n a)
-> Alignment
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Int
forall a. Enum a => a -> Int
fromEnum (Integer -> Int)
-> (Proxy (AlignedPtr n a) -> Integer)
-> Proxy (AlignedPtr n a)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n -> Integer)
-> (Proxy (AlignedPtr n a) -> Proxy n)
-> Proxy (AlignedPtr n a)
-> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (AlignedPtr n a) -> Proxy n
forall (n :: Nat) a. Proxy (AlignedPtr n a) -> Proxy n
coerce
where coerce :: Proxy (AlignedPtr n a) -> Proxy n
coerce :: forall (n :: Nat) a. Proxy (AlignedPtr n a) -> Proxy n
coerce = Proxy n -> Proxy (AlignedPtr n a) -> Proxy n
forall a b. a -> b -> a
const Proxy n
forall {k} (t :: k). Proxy t
Proxy
instance Unbox w => Unbox (BYTES w)
newtype instance MVector s (BYTES w) = MV_BYTES (MVector s w)
newtype instance Vector (BYTES w) = V_BYTES (Vector w)
instance Unbox w => GVM.MVector MVector (BYTES w) where
{-# INLINE basicLength #-}
{-# INLINE basicUnsafeSlice #-}
{-# INLINE basicOverlaps #-}
{-# INLINE basicUnsafeNew #-}
{-# INLINE basicUnsafeReplicate #-}
{-# INLINE basicUnsafeRead #-}
{-# INLINE basicUnsafeWrite #-}
{-# INLINE basicClear #-}
{-# INLINE basicSet #-}
{-# INLINE basicUnsafeCopy #-}
{-# INLINE basicUnsafeGrow #-}
basicLength :: forall s. MVector s (BYTES w) -> Int
basicLength (MV_BYTES MVector s w
v) = MVector s w -> Int
forall s. MVector s w -> Int
forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
GVM.basicLength MVector s w
v
basicUnsafeSlice :: forall s. Int -> Int -> MVector s (BYTES w) -> MVector s (BYTES w)
basicUnsafeSlice Int
i Int
n (MV_BYTES MVector s w
v) = MVector s w -> MVector s (BYTES w)
forall s w. MVector s w -> MVector s (BYTES w)
MV_BYTES (MVector s w -> MVector s (BYTES w))
-> MVector s w -> MVector s (BYTES w)
forall a b. (a -> b) -> a -> b
$ Int -> Int -> MVector s w -> MVector s w
forall s. Int -> Int -> MVector s w -> MVector s w
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
GVM.basicUnsafeSlice Int
i Int
n MVector s w
v
basicOverlaps :: forall s. MVector s (BYTES w) -> MVector s (BYTES w) -> Bool
basicOverlaps (MV_BYTES MVector s w
v1) (MV_BYTES MVector s w
v2) = MVector s w -> MVector s w -> Bool
forall s. MVector s w -> MVector s w -> Bool
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
GVM.basicOverlaps MVector s w
v1 MVector s w
v2
basicUnsafeRead :: forall s. MVector s (BYTES w) -> Int -> ST s (BYTES w)
basicUnsafeRead (MV_BYTES MVector s w
v) Int
i = w -> BYTES w
forall a. a -> BYTES a
BYTES (w -> BYTES w) -> ST s w -> ST s (BYTES w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MVector s w -> Int -> ST s w
forall s. MVector s w -> Int -> ST s w
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s a
GVM.basicUnsafeRead MVector s w
v Int
i
basicUnsafeWrite :: forall s. MVector s (BYTES w) -> Int -> BYTES w -> ST s ()
basicUnsafeWrite (MV_BYTES MVector s w
v) Int
i (BYTES w
x) = MVector s w -> Int -> w -> ST s ()
forall s. MVector s w -> Int -> w -> ST s ()
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> a -> ST s ()
GVM.basicUnsafeWrite MVector s w
v Int
i w
x
basicClear :: forall s. MVector s (BYTES w) -> ST s ()
basicClear (MV_BYTES MVector s w
v) = MVector s w -> ST s ()
forall s. MVector s w -> ST s ()
forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
GVM.basicClear MVector s w
v
basicSet :: forall s. MVector s (BYTES w) -> BYTES w -> ST s ()
basicSet (MV_BYTES MVector s w
v) (BYTES w
x) = MVector s w -> w -> ST s ()
forall s. MVector s w -> w -> ST s ()
forall (v :: * -> * -> *) a s. MVector v a => v s a -> a -> ST s ()
GVM.basicSet MVector s w
v w
x
basicUnsafeNew :: forall s. Int -> ST s (MVector s (BYTES w))
basicUnsafeNew Int
n = MVector s w -> MVector s (BYTES w)
forall s w. MVector s w -> MVector s (BYTES w)
MV_BYTES (MVector s w -> MVector s (BYTES w))
-> ST s (MVector s w) -> ST s (MVector s (BYTES w))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ST s (MVector s w)
forall s. Int -> ST s (MVector s w)
forall (v :: * -> * -> *) a s. MVector v a => Int -> ST s (v s a)
GVM.basicUnsafeNew Int
n
basicUnsafeReplicate :: forall s. Int -> BYTES w -> ST s (MVector s (BYTES w))
basicUnsafeReplicate Int
n (BYTES w
x) = MVector s w -> MVector s (BYTES w)
forall s w. MVector s w -> MVector s (BYTES w)
MV_BYTES (MVector s w -> MVector s (BYTES w))
-> ST s (MVector s w) -> ST s (MVector s (BYTES w))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> w -> ST s (MVector s w)
forall s. Int -> w -> ST s (MVector s w)
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> a -> ST s (v s a)
GVM.basicUnsafeReplicate Int
n w
x
basicUnsafeCopy :: forall s. MVector s (BYTES w) -> MVector s (BYTES w) -> ST s ()
basicUnsafeCopy (MV_BYTES MVector s w
v1) (MV_BYTES MVector s w
v2) = MVector s w -> MVector s w -> ST s ()
forall s. MVector s w -> MVector s w -> ST s ()
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
GVM.basicUnsafeCopy MVector s w
v1 MVector s w
v2
basicUnsafeGrow :: forall s. MVector s (BYTES w) -> Int -> ST s (MVector s (BYTES w))
basicUnsafeGrow (MV_BYTES MVector s w
v) Int
n = MVector s w -> MVector s (BYTES w)
forall s w. MVector s w -> MVector s (BYTES w)
MV_BYTES (MVector s w -> MVector s (BYTES w))
-> ST s (MVector s w) -> ST s (MVector s (BYTES w))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MVector s w -> Int -> ST s (MVector s w)
forall s. MVector s w -> Int -> ST s (MVector s w)
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s (v s a)
GVM.basicUnsafeGrow MVector s w
v Int
n
basicInitialize :: forall s. MVector s (BYTES w) -> ST s ()
basicInitialize (MV_BYTES MVector s w
v) = MVector s w -> ST s ()
forall s. MVector s w -> ST s ()
forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
GVM.basicInitialize MVector s w
v
instance Unbox w => GV.Vector Vector (BYTES w) where
{-# INLINE basicUnsafeFreeze #-}
{-# INLINE basicUnsafeThaw #-}
{-# INLINE basicLength #-}
{-# INLINE basicUnsafeSlice #-}
{-# INLINE basicUnsafeIndexM #-}
{-# INLINE elemseq #-}
basicUnsafeFreeze :: forall s. Mutable Vector s (BYTES w) -> ST s (Vector (BYTES w))
basicUnsafeFreeze (MV_BYTES MVector s w
v) = Vector w -> Vector (BYTES w)
forall w. Vector w -> Vector (BYTES w)
V_BYTES (Vector w -> Vector (BYTES w))
-> ST s (Vector w) -> ST s (Vector (BYTES w))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mutable Vector s w -> ST s (Vector w)
forall s. Mutable Vector s w -> ST s (Vector w)
forall (v :: * -> *) a s. Vector v a => Mutable v s a -> ST s (v a)
GV.basicUnsafeFreeze Mutable Vector s w
MVector s w
v
basicUnsafeThaw :: forall s. Vector (BYTES w) -> ST s (Mutable Vector s (BYTES w))
basicUnsafeThaw (V_BYTES Vector w
v) = MVector s w -> MVector s (BYTES w)
forall s w. MVector s w -> MVector s (BYTES w)
MV_BYTES (MVector s w -> MVector s (BYTES w))
-> ST s (MVector s w) -> ST s (MVector s (BYTES w))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector w -> ST s (Mutable Vector s w)
forall s. Vector w -> ST s (Mutable Vector s w)
forall (v :: * -> *) a s. Vector v a => v a -> ST s (Mutable v s a)
GV.basicUnsafeThaw Vector w
v
basicLength :: Vector (BYTES w) -> Int
basicLength (V_BYTES Vector w
v) = Vector w -> Int
forall (v :: * -> *) a. Vector v a => v a -> Int
GV.basicLength Vector w
v
basicUnsafeSlice :: Int -> Int -> Vector (BYTES w) -> Vector (BYTES w)
basicUnsafeSlice Int
i Int
n (V_BYTES Vector w
v) = Vector w -> Vector (BYTES w)
forall w. Vector w -> Vector (BYTES w)
V_BYTES (Vector w -> Vector (BYTES w)) -> Vector w -> Vector (BYTES w)
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Vector w -> Vector w
forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
GV.basicUnsafeSlice Int
i Int
n Vector w
v
basicUnsafeIndexM :: Vector (BYTES w) -> Int -> Box (BYTES w)
basicUnsafeIndexM (V_BYTES Vector w
v) Int
i = w -> BYTES w
forall a. a -> BYTES a
BYTES (w -> BYTES w) -> Box w -> Box (BYTES w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector w -> Int -> Box w
forall (v :: * -> *) a. Vector v a => v a -> Int -> Box a
GV.basicUnsafeIndexM Vector w
v Int
i
basicUnsafeCopy :: forall s. Mutable Vector s (BYTES w) -> Vector (BYTES w) -> ST s ()
basicUnsafeCopy (MV_BYTES MVector s w
mv) (V_BYTES Vector w
v) = Mutable Vector s w -> Vector w -> ST s ()
forall s. Mutable Vector s w -> Vector w -> ST s ()
forall (v :: * -> *) a s.
Vector v a =>
Mutable v s a -> v a -> ST s ()
GV.basicUnsafeCopy Mutable Vector s w
MVector s w
mv Vector w
v
elemseq :: forall b. Vector (BYTES w) -> BYTES w -> b -> b
elemseq Vector (BYTES w)
_ (BYTES w
x) = Vector w -> w -> b -> b
forall b. Vector w -> w -> b -> b
forall (v :: * -> *) a b. Vector v a => v a -> a -> b -> b
GV.elemseq (Vector a
forall {a}. Vector a
forall a. HasCallStack => a
undefined :: Vector a) w
x