Modulebase-compat-0.14.1Haskell2010
Foreign.Compat
- 23 types
- 3 classes
- 114 values
- Packagebase-compat-0.14.1
- Exports140
- LanguageHaskell2010
- LicenceMIT
- SourceBits.hs
Default implementation for testBit.
Note that: testBitDefault x i = (x .&. bit i) /= 0
Default implementation for popCount.
This implementation is intentionally naive. Instances are expected to provide an optimized implementation for their size.
Infix version of xor.
Infix version of shiftR.
Infix version of shiftL.
Infix version of unsafeShiftR.
Infix version of unsafeShiftL.
Attempt to convert an Integral type a to an Integral type b using
the size of the types as measured by Bits methods.
A simpler version of this function is:
toIntegral :: (Integral a, Integral b) => a -> Maybe b
toIntegral x
| toInteger x == toInteger y = Just y
| otherwise = Nothing
where
y = fromIntegral xThis version requires going through Integer, which can be inefficient.
However, toIntegralSized is optimized to allow GHC to statically determine
the relative type sizes (as measured by bitSizeMaybe and isSigned) and
avoid going through Integer for many types. (The implementation uses
fromIntegral, which is itself optimized with rules for base types but may
go through Integer for some type pairs.)
A more concise version of complement zeroBits.
complement (zeroBits :: Word) == (oneBits :: Word)True
complement (oneBits :: Word) == (zeroBits :: Word)True
Note
The constraint on oneBits is arguably too strong. However, as some types
(such as Natural) have undefined complement, this is the only safe
choice.
The Bits class defines bitwise operations over integral types.
Bits are numbered from 0 with bit 0 being the least significant bit.
Methods
(.&.) :: a -> a -> ainfixl 7Bitwise "and"
(.|.) :: a -> a -> ainfixl 5Bitwise "or"
xor :: a -> a -> ainfixl 6Bitwise "xor"
complement :: a -> aReverse all the bits in the argument
shift :: a -> Int -> ainfixl 8shift x ishiftsxleft byibits ifiis positive, or right by-ibits otherwise. Right shifts perform sign extension on signed number types; i.e. they fill the top bits with 1 if thexis negative and with 0 otherwise.An instance can define either this unified shift or shiftL and shiftR, depending on which is more convenient for the type in question.
rotate :: a -> Int -> ainfixl 8zeroBits :: azeroBits is the value with all bits unset.
The following laws ought to hold (for all valid bit indices
n):clearBit zeroBits n == zeroBitssetBit zeroBits n == bit ntestBit zeroBits n == FalsepopCount zeroBits == 0
This method uses
clearBit (bit 0) 0as its default implementation (which ought to be equivalent to zeroBits for types which possess a 0th bit).bit :: Int -> asetBit :: a -> Int -> ax `setBit` iis the same asx .|. bit iclearBit :: a -> Int -> ax `clearBit` iis the same asx .&. complement (bit i)complementBit :: a -> Int -> ax `complementBit` iis the same asx `xor` bit itestBit :: a -> Int -> Boolx `testBit` iis the same asx .&. bit n /= 0In other words it returns True if the bit at offset @n is set.
Can be implemented using
testBitDefaultifais also an instance of Num.bitSizeMaybe :: a -> Maybe IntReturn the number of bits in the type of the argument. The actual value of the argument is ignored. Returns Nothing for types that do not have a fixed bitsize, like Integer.
bitSize :: a -> IntReturn the number of bits in the type of the argument. The actual value of the argument is ignored. The function bitSize is undefined for types that do not have a fixed bitsize, like Integer.
Default implementation based upon bitSizeMaybe provided since 4.12.0.0.
isSigned :: a -> BoolReturn True if the argument is a signed type. The actual value of the argument is ignored
shiftL :: a -> Int -> ainfixl 8unsafeShiftL :: a -> Int -> ashiftR :: a -> Int -> ainfixl 8Shift the first argument right by the specified number of bits. The result is undefined for negative shift amounts and shift amounts greater or equal to the bitSize. Some instances may throw an Overflow exception if given a negative input.
Right shifts perform sign extension on signed number types; i.e. they fill the top bits with 1 if the
xis negative and with 0 otherwise.An instance can define either this and shiftL or the unified shift, depending on which is more convenient for the type in question.
unsafeShiftR :: a -> Int -> aShift the first argument right by the specified number of bits, which must be non-negative and smaller than the number of bits in the type.
Right shifts perform sign extension on signed number types; i.e. they fill the top bits with 1 if the
xis negative and with 0 otherwise.Defaults to shiftR unless defined explicitly by an instance.
rotateL :: a -> Int -> ainfixl 8rotateR :: a -> Int -> ainfixl 8popCount :: a -> IntReturn the number of set bits in the argument. This number is known as the population count or the Hamming weight.
Can be implemented using
popCountDefaultifais also an instance of Num.
Instances68Bits, …
Bits IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsBits NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsBits EventTypeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.EPollBits EventDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.PollBits CBoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CLLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CPtrdiffDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CSCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CSigAtomicDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CUCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CUIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CUIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CUIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CULLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CULongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CUShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits CWcharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesBits IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrBits WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrBits Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntBits Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntBits Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntBits Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntBits CBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CBlkSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CClockIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CDevDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CFsBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CFsFilCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CGidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CInoDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CKeyDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CModeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CNfdsDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CNlinkDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits COffDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CPidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CRLimDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CSocklenDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CSsizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CTcflagDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits CUidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesBits Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordBits Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordBits Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordBits Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordBits BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsInterpret Bool as 1-bit bit-field
Bits IntDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsBits WordDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsBits CAttributesDefined in unix-2.8.7.0 · System.Posix.Files.CommonBits StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonBits StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonBits a => Bits (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Bits (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Bits (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Bits (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Bits (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityBits a => Bits (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.OrdBits a => Bits (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Const
A fixed-precision integer type with at least the range [-2^29 .. 2^29-1].
The exact range for a given implementation can be determined by using
Prelude.minBound and Prelude.maxBound from the Prelude.Bounded class.
Instances34Bounded, Enum, Integral, Data, Num, Read, …
Bounded IntDefined in ghc-internal-9.1003.0 · GHC.Internal.EnumEnum IntDefined in ghc-internal-9.1003.0 · GHC.Internal.EnumEq IntDefined in ghc-prim-0.12.0 · GHC.ClassesIntegral IntDefined in ghc-internal-9.1003.0 · GHC.Internal.RealData IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum IntDefined in ghc-internal-9.1003.0 · GHC.Internal.NumOrd IntDefined in ghc-prim-0.12.0 · GHC.ClassesRead IntDefined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal IntDefined in ghc-internal-9.1003.0 · GHC.Internal.RealShow IntDefined in ghc-internal-9.1003.0 · GHC.Internal.ShowIx IntDefined in ghc-internal-9.1003.0 · GHC.Internal.IxBits IntDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsFiniteBits IntDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsStorable IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg IntDefined in base-4.20.2.0 · Text.PrintfNFData IntDefined in deepseq-1.5.0.0 · Control.DeepSeqPretty IntDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJClassPretty IntDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJClassShowPadded IntDefined in time-1.12.2 · Data.Time.Calendar.PrivateLift IntDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray IntDefined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Int IODefined in array-0.5.8.0 · Data.Array.IO.InternalsGeneric1 (URec Int)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsFoldable UIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableTraversable UIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.TraversableMArray (STUArray s) Int (ST s)Defined in array-0.5.8.0 · Data.Array.BaseFunctor (URec Int)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsEq (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsOrd (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsShow (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsGeneric (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Genericstype Rep (URec Int p) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"URec"
"GHC.Internal.Generics"
"ghc-internal"
'False) (C1 ('MetaCons"UInt"
'PrefixI 'True) (S1 ('MetaSel ('Just"uInt#"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UInt))type Rep1 (URec Int) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"URec"
"GHC.Internal.Generics"
"ghc-internal"
'False) (C1 ('MetaCons"UInt"
'PrefixI 'True) (S1 ('MetaSel ('Just"uInt#"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UInt))data URec IntDefined in ghc-internal-9.1003.0 · GHC.Internal.GenericsUsed for marking occurrences of Int#
Reverse order of bytes in Word16.
Reverse order of bytes in Word32.
Reverse order of bytes in Word64.
Instances31Bounded, Enum, Integral, Data, Num, Read, …
Bounded WordDefined in ghc-internal-9.1003.0 · GHC.Internal.EnumEnum WordDefined in ghc-internal-9.1003.0 · GHC.Internal.EnumEq WordDefined in ghc-prim-0.12.0 · GHC.ClassesIntegral WordDefined in ghc-internal-9.1003.0 · GHC.Internal.RealData WordDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum WordDefined in ghc-internal-9.1003.0 · GHC.Internal.NumOrd WordDefined in ghc-prim-0.12.0 · GHC.ClassesRead WordDefined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal WordDefined in ghc-internal-9.1003.0 · GHC.Internal.RealShow WordDefined in ghc-internal-9.1003.0 · GHC.Internal.ShowIx WordDefined in ghc-internal-9.1003.0 · GHC.Internal.IxBits WordDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsFiniteBits WordDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsStorable WordDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg WordDefined in base-4.20.2.0 · Text.PrintfNFData WordDefined in deepseq-1.5.0.0 · Control.DeepSeqLift WordDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray WordDefined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Word IODefined in array-0.5.8.0 · Data.Array.IO.InternalsGeneric1 (URec Word)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsFoldable UWordDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableTraversable UWordDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.TraversableMArray (STUArray s) Word (ST s)Defined in array-0.5.8.0 · Data.Array.BaseFunctor (URec Word)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsEq (URec Word p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsOrd (URec Word p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsShow (URec Word p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsGeneric (URec Word p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Genericstype Rep (URec Word p) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"URec"
"GHC.Internal.Generics"
"ghc-internal"
'False) (C1 ('MetaCons"UWord"
'PrefixI 'True) (S1 ('MetaSel ('Just"uWord#"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UWord))type Rep1 (URec Word) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"URec"
"GHC.Internal.Generics"
"ghc-internal"
'False) (C1 ('MetaCons"UWord"
'PrefixI 'True) (S1 ('MetaSel ('Just"uWord#"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UWord))data URec WordDefined in ghc-internal-9.1003.0 · GHC.Internal.GenericsUsed for marking occurrences of Word#
Advances the given address by the given offset in bytes.
The new ForeignPtr shares the finalizer of the original, equivalent from a finalization standpoint to just creating another reference to the original. That is, the finalizer will not be called before the new ForeignPtr is unreachable, nor will it be called an additional time due to this call, and the finalizer will be called with the same address that it would have had this call not happened, *not* the new address.
The type ForeignPtr represents references to objects that are
maintained in a foreign language, i.e., that are not part of the
data structures usually managed by the Haskell storage manager.
The essential difference between ForeignPtrs and vanilla memory
references of type Ptr a is that the former may be associated
with finalizers. A finalizer is a routine that is invoked when
the Haskell storage manager detects that - within the Haskell heap
and stack - there are no more references left that are pointing to
the ForeignPtr. Typically, the finalizer will, then, invoke
routines in the foreign language that free the resources bound by
the foreign object.
The ForeignPtr is parameterised in the same way as Ptr. The type argument of ForeignPtr should normally be an instance of class Storable.
Instances4Eq, Data, Ord, Show
Eq (ForeignPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.ForeignPtrData a => Data (ForeignPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataOrd (ForeignPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.ForeignPtrShow (ForeignPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.ForeignPtr
A finalizer is represented as a pointer to a foreign function that, at finalisation time, gets as an argument a plain pointer variant of the foreign pointer that the finalizer is associated with.
Note that the foreign function must either use the ccall or the capi calling convention.
Turns a plain memory reference into a foreign pointer, and associates a finalizer with the reference. The finalizer will be executed after the last reference to the foreign object is dropped. There is no guarantee of promptness, however the finalizer will be executed before the program exits.
Turns a plain memory reference into a foreign pointer that may be associated with finalizers by using addForeignPtrFinalizer.
This function adds a finalizer to the given foreign object. The finalizer will run before all other finalizers for the same object which have already been registered.
This variant of newForeignPtr adds a finalizer that expects an environment in addition to the finalized pointer. The environment that will be passed to the finalizer is fixed by the second argument to newForeignPtrEnv.
Like addForeignPtrFinalizer but the finalizer is passed an additional environment parameter.
This is a way to look at the pointer living inside a foreign object. This function takes a function which is applied to that pointer. The resulting IO action is then executed. The foreign object is kept alive at least during the whole action, even if it is not used directly inside. Note that it is not safe to return the pointer from the action and use it after the action completes. All uses of the pointer should be inside the withForeignPtr bracket. The reason for this unsafeness is the same as for unsafeForeignPtrToPtr below: the finalizer may run earlier than expected, because the compiler can only track usage of the ForeignPtr object, not a Ptr object made from it.
This function is normally used for marshalling data to or from the object pointed to by the ForeignPtr, using the operations from the Storable class.
Causes the finalizers associated with a foreign pointer to be run immediately. The foreign pointer must not be used again after this function is called. If the foreign pointer does not support finalizers, this is a no-op.
This function ensures that the foreign object in
question is alive at the given place in the sequence of IO
actions. However, this comes with a significant caveat: the contract above
does not hold if GHC can demonstrate that the code preceding
touchForeignPtr diverges (e.g. by looping infinitely or throwing an
exception). For this reason, you are strongly advised to use instead
withForeignPtr where possible.
Also, note that this function should not be used to express dependencies
between finalizers on ForeignPtrs. For example, if the finalizer for a
ForeignPtr F1 calls touchForeignPtr on a second ForeignPtr F2,
then the only guarantee is that the finalizer for F2 is never started
before the finalizer for F1. They might be started together if for
example both F1 and F2 are otherwise unreachable, and in that case the
scheduler might end up running the finalizer for F2 first.
In general, it is not recommended to use finalizers on separate
objects with ordering constraints between them. To express the
ordering robustly requires explicit synchronisation using MVars
between the finalizers, but even then the runtime sometimes runs
multiple finalizers sequentially in a single thread (for
performance reasons), so synchronisation between finalizers could
result in artificial deadlock. Another alternative is to use
explicit reference counting.
This function casts a ForeignPtr parameterised by one type into another type.
Allocate some memory and return a ForeignPtr to it. The memory will be released automatically when the ForeignPtr is discarded.
mallocForeignPtr is equivalent to
do { p <- malloc; newForeignPtr finalizerFree p }although it may be implemented differently internally: you may not assume that the memory returned by mallocForeignPtr has been allocated with malloc.
GHC notes: mallocForeignPtr has a heavily optimised implementation in GHC. It uses pinned memory in the garbage collected heap, so the ForeignPtr does not require a finalizer to free the memory. Use of mallocForeignPtr and associated functions is strongly recommended in preference to newForeignPtr with a finalizer.
This function is similar to mallocForeignPtr, except that the size of the memory required is given explicitly as a number of bytes.
This function is similar to mallocArray, but yields a memory area that has a finalizer attached that releases the memory area. As with mallocForeignPtr, it is not guaranteed that the block of memory was allocated by malloc.
This function is similar to mallocArray0, but yields a memory area that has a finalizer attached that releases the memory area. As with mallocForeignPtr, it is not guaranteed that the block of memory was allocated by malloc.
Like malloc but memory is filled with bytes of value zero.
Like mallocBytes, but memory is filled with bytes of value zero.
Like mallocArray, but allocated memory is filled with bytes of value zero.
Like callocArray0, but allocated memory is filled with bytes of value zero.
A memory pool.
Fill a given number of bytes in memory area with a byte value.
The member functions of this class facilitate writing values of primitive types to raw memory (which may have been allocated with the above mentioned routines) and reading values from blocks of raw memory. The class, furthermore, includes support for computing the storage requirements and alignment restrictions of storable types.
Memory addresses are represented as values of type Ptr a, for some
a which is an instance of class Storable. The type argument to
Ptr helps provide some valuable type safety in FFI code (you can't
mix pointers of different types without an explicit cast), while
helping the Haskell type system figure out which marshalling method is
needed for a given pointer.
All marshalling between Haskell and a foreign language ultimately
boils down to translating Haskell data structures into the binary
representation of a corresponding data structure of the foreign
language and vice versa. To code this marshalling in Haskell, it is
necessary to manipulate primitive data types stored in unstructured
memory blocks. The class Storable facilitates this manipulation on
all types for which it is instantiated, which are the standard basic
types of Haskell, the fixed size Int types (Int8, Int16,
Int32, Int64), the fixed size Word types (Word8, Word16,
Word32, Word64), StablePtr, all types from Foreign.C.Types,
as well as Ptr.
Methods
sizeOf :: a -> IntComputes the storage requirements (in bytes) of the argument. The value of the argument is not used.
alignment :: a -> IntComputes the alignment constraint of the argument. An alignment constraint
xis fulfilled by any address divisible byx. The alignment must be a power of two if this instance is to be used withallocaorallocaArray. The value of the argument is not used.peekElemOff :: Ptr a -> Int -> IO aRead a value from a memory area regarded as an array of values of the same kind. The first argument specifies the start address of the array and the second the index into the array (the first element of the array has index
0). The following equality holds,peekElemOff addr idx = IOExts.fixIO $ \result -> peek (addr `plusPtr` (idx * sizeOf result))Note that this is only a specification, not necessarily the concrete implementation of the function.
pokeElemOff :: Ptr a -> Int -> a -> IO ()Write a value to a memory area regarded as an array of values of the same kind. The following equality holds:
pokeElemOff addr idx x = poke (addr `plusPtr` (idx * sizeOf x)) xpeekByteOff :: Ptr b -> Int -> IO aRead a value from a memory location given by a base address and offset. The following equality holds:
peekByteOff addr off = peek (addr `plusPtr` off)pokeByteOff :: Ptr b -> Int -> a -> IO ()Write a value to a memory location given by a base address and offset. The following equality holds:
pokeByteOff addr off x = poke (addr `plusPtr` off) xpeek :: Ptr a -> IO aRead a value from the given memory location.
Note that the peek and poke functions might require properly aligned addresses to function correctly. This is architecture dependent; thus, portable code should ensure that when peeking or poking values of some type
a, the alignment constraint fora, as given by the function alignment is fulfilled.poke :: Ptr a -> a -> IO ()Write the given value to the given memory location. Alignment restrictions might apply; see peek.
Instances88Storable, …
Storable EventDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.EPollStorable EventDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.PollStorable PollFdDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.PollStorable FingerprintDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable CBoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CClockDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CDoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CFloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CLLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CPtrdiffDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CSCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CSUSecondsDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CSigAtomicDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CTimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CUCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CUIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CUIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CUIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CULLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CULongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CUSecondsDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CUShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable CWcharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesStorable IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrStorable WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrStorable FLockDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Handle.Lock.LinuxOFDStorable Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable IoSubSystemDefined in ghc-internal-9.1003.0 · GHC.Internal.RTS.FlagsStorable CBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CBlkSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CCcDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CClockIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CDevDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CFsBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CFsFilCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CGidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CInoDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CKeyDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CModeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CNfdsDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CNlinkDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable COffDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CPidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CRLimDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CSocklenDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CSpeedDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CSsizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CTcflagDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CTimerDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable CUidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesStorable Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable CharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable WordDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable CTimespecDefined in time-1.12.2 · Data.Time.Clock.Internal.CTimespecStorable CTimevalDefined in time-1.12.2 · Data.Time.Clock.Internal.CTimevalStorable DirEntDefined in unix-2.8.7.0 · System.Posix.Directory.CommonStorable CAttributesDefined in unix-2.8.7.0 · System.Posix.Files.CommonStorable CTimeSpecDefined in unix-2.8.7.0 · System.Posix.Files.CommonStorable CTimeValDefined in unix-2.8.7.0 · System.Posix.Files.CommonStorable ()Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable (ConstPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable (FunPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable (Ptr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable (StablePtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable a => Storable (Complex a)Defined in base-4.20.2.0 · Data.ComplexStorable a => Storable (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityStorable a => Storable (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Ord(Storable a, Integral a) => Storable (Ratio a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableStorable a => Storable (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Const
A value of type Ptr a represents a pointer to an object, or an
array of objects, which may be marshalled to or from Haskell values
of type a.
The type a will often be an instance of class
Storable which provides the marshalling operations.
However this is not essential, and you can provide your own operations
to access the pointer. For example you might write small foreign
functions to get or set the fields of a C struct.
Instances20NFData1, IArray, Generic1, Data, Show, Foldable, …
NFData1 PtrDefined in deepseq-1.5.0.0 · Control.DeepSeqIArray UArray (Ptr a)Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray (Ptr a) IODefined in array-0.5.8.0 · Data.Array.IO.InternalsGeneric1 (URec (Ptr ()))Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsEq (Ptr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.PtrData a => Data (Ptr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataOrd (Ptr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.PtrShow (Ptr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.PtrFoldable UAddrDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableTraversable UAddrDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.TraversableStorable (Ptr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableNFData (Ptr a)Defined in deepseq-1.5.0.0 · Control.DeepSeqMArray (STUArray s) (Ptr a) (ST s)Defined in array-0.5.8.0 · Data.Array.BaseFunctor (URec (Ptr ()))Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsEq (URec (Ptr ()) p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsOrd (URec (Ptr ()) p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsGeneric (URec (Ptr ()) p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Genericstype Rep (URec (Ptr ()) p) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"URec"
"GHC.Internal.Generics"
"ghc-internal"
'False) (C1 ('MetaCons"UAddr"
'PrefixI 'True) (S1 ('MetaSel ('Just"uAddr#"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UAddr))type Rep1 (URec (Ptr ())) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"URec"
"GHC.Internal.Generics"
"ghc-internal"
'False) (C1 ('MetaCons"UAddr"
'PrefixI 'True) (S1 ('MetaSel ('Just"uAddr#"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UAddr))data URec (Ptr ())Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsUsed for marking occurrences of Addr#
A value of type FunPtr a is a pointer to a function callable
from foreign code. The type a will normally be a foreign type,
a function type with zero or more arguments where
the argument types are marshallable foreign types, i.e. Char, Int, Double, Float, Bool, Int8, Int16, Int32, Int64, Word8, Word16, Word32, Word64,
Ptr a,FunPtr a,StablePtr aor a renaming of any of these usingnewtype.the return type is either a marshallable foreign type or has the form
IO twheretis a marshallable foreign type or().
A value of type FunPtr a may be a pointer to a foreign function,
either returned by another foreign function or imported with a
a static address import like
foreign import ccall "stdlib.h &free"
p_free :: FunPtr (Ptr a -> IO ())or a pointer to a Haskell function created using a wrapper stub declared to produce a FunPtr of the correct type. For example:
type Compare = Int -> Int -> Bool
foreign import ccall "wrapper"
mkCompare :: Compare -> IO (FunPtr Compare)Calls to wrapper stubs like mkCompare allocate storage, which
should be released with freeHaskellFunPtr when no
longer required.
To convert FunPtr values to corresponding Haskell functions, one can define a dynamic stub for the specific foreign type, e.g.
type IntFunction = CInt -> IO ()
foreign import ccall "dynamic"
mkFun :: FunPtr IntFunction -> IntFunctionInstances9NFData1, IArray, Eq, Ord, Show, Storable, …
NFData1 FunPtrDefined in deepseq-1.5.0.0 · Control.DeepSeqIArray UArray (FunPtr a)Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray (FunPtr a) IODefined in array-0.5.8.0 · Data.Array.IO.InternalsEq (FunPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.PtrOrd (FunPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.PtrShow (FunPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.PtrStorable (FunPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableNFData (FunPtr a)Defined in deepseq-1.5.0.0 · Control.DeepSeqMArray (STUArray s) (FunPtr a) (ST s)Defined in array-0.5.8.0 · Data.Array.Base
32-bit unsigned integer type
Instances21Bounded, Enum, Eq, Integral, Data, Num, …
Bounded Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEnum Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEq Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIntegral Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordData Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordOrd Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordRead Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordShow Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIx Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordBits Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordFiniteBits Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordStorable Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg Word32Defined in base-4.20.2.0 · Text.PrintfNFData Word32Defined in deepseq-1.5.0.0 · Control.DeepSeqMantissa Word32Defined in bytestring-0.12.2.0 · Data.ByteString.Builder.RealFloat.InternalLift Word32Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray Word32Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Word32 IODefined in array-0.5.8.0 · Data.Array.IO.InternalsMArray (STUArray s) Word32 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
64-bit unsigned integer type
Instances21Bounded, Enum, Eq, Integral, Data, Num, …
Bounded Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEnum Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEq Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIntegral Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordData Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordOrd Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordRead Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordShow Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIx Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordBits Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordFiniteBits Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordStorable Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg Word64Defined in base-4.20.2.0 · Text.PrintfNFData Word64Defined in deepseq-1.5.0.0 · Control.DeepSeqMantissa Word64Defined in bytestring-0.12.2.0 · Data.ByteString.Builder.RealFloat.InternalLift Word64Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray Word64Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Word64 IODefined in array-0.5.8.0 · Data.Array.IO.InternalsMArray (STUArray s) Word64 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
16-bit unsigned integer type
Instances20Bounded, Enum, Eq, Integral, Data, Num, …
Bounded Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEnum Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEq Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIntegral Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordData Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordOrd Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordRead Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordShow Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIx Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordBits Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordFiniteBits Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordStorable Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg Word16Defined in base-4.20.2.0 · Text.PrintfNFData Word16Defined in deepseq-1.5.0.0 · Control.DeepSeqLift Word16Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray Word16Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Word16 IODefined in array-0.5.8.0 · Data.Array.IO.InternalsMArray (STUArray s) Word16 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
8-bit unsigned integer type
Instances20Bounded, Enum, Eq, Integral, Data, Num, …
Bounded Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEnum Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordEq Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIntegral Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordData Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordOrd Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordRead Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordShow Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordIx Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordBits Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordFiniteBits Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordStorable Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg Word8Defined in base-4.20.2.0 · Text.PrintfNFData Word8Defined in deepseq-1.5.0.0 · Control.DeepSeqLift Word8Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray Word8Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Word8 IODefined in array-0.5.8.0 · Data.Array.IO.InternalsMArray (STUArray s) Word8 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
The FiniteBits class denotes types with a finite, fixed number of bits.
Methods
finiteBitSize :: b -> IntReturn the number of bits in the type of the argument. The actual value of the argument is ignored. Moreover, finiteBitSize is total, in contrast to the deprecated bitSize function it replaces.
finiteBitSize = bitSize bitSizeMaybe = Just . finiteBitSizecountLeadingZeros :: b -> IntCount number of zero bits preceding the most significant set bit.
countLeadingZeros (zeroBits :: a) = finiteBitSize (zeroBits :: a)countLeadingZeros can be used to compute log base 2 via
logBase2 x = finiteBitSize x - 1 - countLeadingZeros xNote: The default implementation for this method is intentionally naive. However, the instances provided for the primitive integral types are implemented using CPU specific machine instructions.
countTrailingZeros :: b -> IntCount number of zero bits following the least significant set bit.
countTrailingZeros (zeroBits :: a) = finiteBitSize (zeroBits :: a) countTrailingZeros . negate = countTrailingZerosThe related find-first-set operation can be expressed in terms of countTrailingZeros as follows
findFirstSet x = 1 + countTrailingZeros xNote: The default implementation for this method is intentionally naive. However, the instances provided for the primitive integral types are implemented using CPU specific machine instructions.
Instances63FiniteBits, …
FiniteBits EventTypeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.EPollFiniteBits EventDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.PollFiniteBits CBoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CLLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CPtrdiffDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CSCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CSigAtomicDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CUCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CUIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CUIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CUIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CULLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CULongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CUShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits CWcharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.TypesFiniteBits IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrFiniteBits WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrFiniteBits Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntFiniteBits Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntFiniteBits Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntFiniteBits Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntFiniteBits CBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CBlkSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CClockIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CDevDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CFsBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CFsFilCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CGidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CInoDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CKeyDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CModeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CNfdsDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CNlinkDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits COffDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CPidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CRLimDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CSocklenDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CSsizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CTcflagDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits CUidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.TypesFiniteBits Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.WordFiniteBits Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.WordFiniteBits Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.WordFiniteBits Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.WordFiniteBits BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsFiniteBits IntDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsFiniteBits WordDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsFiniteBits a => FiniteBits (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => FiniteBits (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => FiniteBits (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => FiniteBits (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => FiniteBits (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityFiniteBits a => FiniteBits (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.OrdFiniteBits a => FiniteBits (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Const
64-bit signed integer type
Instances20Bounded, Enum, Eq, Integral, Data, Num, …
Bounded Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntEnum Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntEq Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntIntegral Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntData Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntOrd Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntRead Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntReal Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntShow Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntIx Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntBits Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntFiniteBits Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.IntStorable Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg Int64Defined in base-4.20.2.0 · Text.PrintfNFData Int64Defined in deepseq-1.5.0.0 · Control.DeepSeqLift Int64Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray Int64Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Int64 IODefined in array-0.5.8.0 · Data.Array.IO.InternalsMArray (STUArray s) Int64 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
The castPtr function casts a pointer from one type to another.
The inverse of castStablePtrToPtr, i.e., we have the identity
sp == castPtrToStablePtr (castStablePtrToPtr sp)for any stable pointer sp on which freeStablePtr has
not been executed yet. Moreover, castPtrToStablePtr may
only be applied to pointers that have been produced by
castStablePtrToPtr.
Coerce a stable pointer to an address. No guarantees are made about the resulting value, except that the original stable pointer can be recovered by castPtrToStablePtr. In particular, the address might not refer to an accessible memory location and any attempt to pass it to the member functions of the class Storable leads to undefined behaviour.
Obtain the Haskell value referenced by a stable pointer, i.e., the same value that was passed to the corresponding call to newStablePtr. If the argument to deRefStablePtr has already been freed using freeStablePtr, the behaviour of deRefStablePtr is undefined.
Dissolve the association between the stable pointer and the Haskell
value. Afterwards, if the stable pointer is passed to
deRefStablePtr or freeStablePtr, the behaviour is
undefined. However, the stable pointer may still be passed to
castStablePtrToPtr, but the Ptr () value returned
by castStablePtrToPtr, in this case, is undefined (in particular,
it may be nullPtr). Nevertheless, the call
to castStablePtrToPtr is guaranteed not to diverge.
Create a stable pointer referring to the given Haskell value.
32-bit signed integer type
Instances20Bounded, Enum, Eq, Integral, Data, Num, …
Bounded Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntEnum Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntEq Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntIntegral Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntData Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntOrd Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntRead Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntReal Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntShow Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntIx Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntBits Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntFiniteBits Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.IntStorable Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg Int32Defined in base-4.20.2.0 · Text.PrintfNFData Int32Defined in deepseq-1.5.0.0 · Control.DeepSeqLift Int32Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray Int32Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Int32 IODefined in array-0.5.8.0 · Data.Array.IO.InternalsMArray (STUArray s) Int32 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
16-bit signed integer type
Instances20Bounded, Enum, Eq, Integral, Data, Num, …
Bounded Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntEnum Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntEq Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntIntegral Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntData Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntOrd Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntRead Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntReal Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntShow Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntIx Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntBits Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntFiniteBits Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.IntStorable Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg Int16Defined in base-4.20.2.0 · Text.PrintfNFData Int16Defined in deepseq-1.5.0.0 · Control.DeepSeqLift Int16Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray Int16Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Int16 IODefined in array-0.5.8.0 · Data.Array.IO.InternalsMArray (STUArray s) Int16 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
8-bit signed integer type
Instances20Bounded, Enum, Eq, Integral, Data, Num, …
Bounded Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntEnum Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntEq Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntIntegral Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntData Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntOrd Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntRead Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntReal Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntShow Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntIx Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntBits Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntFiniteBits Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.IntStorable Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorablePrintfArg Int8Defined in base-4.20.2.0 · Text.PrintfNFData Int8Defined in deepseq-1.5.0.0 · Control.DeepSeqLift Int8Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxIArray UArray Int8Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray Int8 IODefined in array-0.5.8.0 · Data.Array.IO.InternalsMArray (STUArray s) Int8 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
A stable pointer is a reference to a Haskell expression that is guaranteed not to be affected by garbage collection, i.e., it will neither be deallocated nor will the value of the stable pointer itself change during garbage collection (ordinary references may be relocated during garbage collection). Consequently, stable pointers can be passed to foreign code, which can treat it as an opaque reference to a Haskell value.
The StablePtr 0 is reserved for representing NULL in foreign code.
A value of type StablePtr a is a stable pointer to a Haskell
expression of type a.
Instances5IArray, Eq, Storable, MArray
IArray UArray (StablePtr a)Defined in array-0.5.8.0 · Data.Array.BaseMArray IOUArray (StablePtr a) IODefined in array-0.5.8.0 · Data.Array.IO.InternalsEq (StablePtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.StableStorable (StablePtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.StorableMArray (STUArray s) (StablePtr a) (ST s)Defined in array-0.5.8.0 · Data.Array.Base
Monoid under bitwise AND.
getAnd (And 0xab <> And 0x12) :: Word82
Instances9Bounded, Enum, Eq, Read, Show, Semigroup, …
Bounded a => Bounded (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsEnum a => Enum (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsEq a => Eq (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsRead a => Read (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsShow a => Show (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Semigroup (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => Monoid (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsThis constraint is arguably too strong. However, as some types (such as
Natural) have undefined complement, this is the only safe choice.Bits a => Bits (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => FiniteBits (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
Monoid under bitwise 'equality'; defined as 1 if the corresponding
bits match, and 0 otherwise.
getIff (Iff 0xab <> Iff 0x12) :: Word870
Instances9Bounded, Enum, Eq, Read, Show, Semigroup, …
Bounded a => Bounded (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsEnum a => Enum (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsEq a => Eq (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsRead a => Read (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsShow a => Show (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => Semigroup (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsThis constraint is arguably too strong. However, as some types (such as
Natural) have undefined complement, this is the only safe choice.FiniteBits a => Monoid (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsThis constraint is arguably too strong. However, as some types (such as
Natural) have undefined complement, this is the only safe choice.Bits a => Bits (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => FiniteBits (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
Monoid under bitwise inclusive OR.
getIor (Ior 0xab <> Ior 0x12) :: Word8187
Instances9Bounded, Enum, Eq, Read, Show, Semigroup, …
Bounded a => Bounded (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsEnum a => Enum (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsEq a => Eq (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsRead a => Read (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsShow a => Show (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Semigroup (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Monoid (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Bits (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => FiniteBits (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
Monoid under bitwise XOR.
getXor (Xor 0xab <> Xor 0x12) :: Word8185
Instances9Bounded, Enum, Eq, Read, Show, Semigroup, …
Bounded a => Bounded (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsEnum a => Enum (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsEq a => Eq (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsRead a => Read (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsShow a => Show (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Semigroup (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Monoid (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Bits (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => FiniteBits (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
alloca f executes the computation f, passing as argument
a pointer to a temporarily allocated block of memory sufficient to
hold values of type a.
The memory is freed when f terminates (either normally or via an
exception), so the pointer passed to f must not be used after this.
allocaBytes n f executes the computation f, passing as argument
a pointer to a temporarily allocated block of memory of n bytes.
The block of memory is sufficiently aligned for any of the basic
foreign types that fits into a memory block of the allocated size.
The memory is freed when f terminates (either normally or via an
exception), so the pointer passed to f must not be used after this.
allocaBytesAligned size align f executes the computation f,
passing as argument a pointer to a temporarily allocated block of memory
of size bytes and aligned to align bytes. The value of align must
be a power of two.
The memory is freed when f terminates (either normally or via an
exception), so the pointer passed to f must not be used after this.
A pointer to a foreign function equivalent to free, which may be used as a finalizer (cf ForeignPtr) for storage allocated with malloc, mallocBytes, realloc or reallocBytes.
Free a block of memory that was allocated with malloc,
mallocBytes, realloc, reallocBytes, new
or any of the newX functions in Foreign.Marshal.Array or
Foreign.C.String.
Allocate a block of memory that is sufficient to hold values of type
a. The size of the area allocated is determined by the sizeOf
method from the instance of Storable for the appropriate type.
The memory may be deallocated using free or finalizerFree when no longer required.
Allocate a block of memory of the given number of bytes. The block of memory is sufficiently aligned for any of the basic foreign types that fits into a memory block of the allocated size.
The memory may be deallocated using free or finalizerFree when no longer required.
Resize a memory area that was allocated with malloc or mallocBytes
to the size needed to store values of type b. The returned pointer
may refer to an entirely different memory area, but will be suitably
aligned to hold values of type b. The contents of the referenced
memory area will be the same as of the original pointer up to the
minimum of the original size and the size of values of type b.
If the argument to realloc is nullPtr, realloc behaves like malloc.
Resize a memory area that was allocated with malloc or mallocBytes to the given size. The returned pointer may refer to an entirely different memory area, but will be sufficiently aligned for any of the basic foreign types that fits into a memory block of the given size. The contents of the referenced memory area will be the same as of the original pointer up to the minimum of the original size and the given size.
If the pointer argument to reallocBytes is nullPtr, reallocBytes behaves like malloc. If the requested size is 0, reallocBytes behaves like free.
Advance a pointer into an array by the given number of elements
Temporarily allocate space for the given number of elements (like alloca, but for multiple elements).
Like allocaArray, but add an extra position to hold a special termination element.
Copy the given number of elements from the second array (source) into the first array (destination); the copied areas may not overlap
Return the number of elements in an array, excluding the terminator
Allocate storage for the given number of elements of a storable type (like malloc, but for multiple elements).
Like mallocArray, but add an extra position to hold a special termination element.
Copy the given number of elements from the second array (source) into the first array (destination); the copied areas may overlap
Write a list of storable elements into a newly allocated, consecutive sequence of storable values (like new, but for multiple elements).
Write a list of storable elements into a newly allocated, consecutive sequence of storable values, where the end is fixed by the given end marker
Convert an array of given length into a Haskell list. The implementation is tail-recursive and so uses constant stack space.
Convert an array terminated by the given end marker into a Haskell list
Write the list elements consecutive into memory
Write the list elements consecutive into memory and terminate them with the given marker element
Adjust the size of an array
Adjust the size of an array including an extra position for the end marker.
Temporarily store a list of storable values in memory (like with, but for multiple elements).
Like withArray, but a terminator indicates where the array ends
Like withArray, but the action gets the number of values as an additional parameter
Like withArrayLen, but a terminator indicates where the array ends
Copies the given number of bytes from the second area (source) into the first (destination); the copied areas may not overlap
Convert a Haskell Bool to its numeric representation
Copies the given number of bytes from the second area (source) into the first (destination); the copied areas may overlap
Convert a Boolean in numeric representation to a Haskell value
with val f executes the computation f, passing as argument
a pointer to a temporarily allocated block of memory into which
val has been marshalled (the combination of alloca and poke).
The memory is freed when f terminates (either normally or via an
exception), so the pointer passed to f must not be used after this.
Replicates a withXXX combinator over a list of objects, yielding a list of
marshalled objects
throwIf Guards against negative result values
Like throwIfNeg, but discarding the result
Guards against null pointers
Like throwIf, but discarding the result
Deallocate a memory pool and everything which has been allocated in the pool itself.
Allocate a fresh memory pool.
Allocate storage for the given number of elements of a storable type in the pool.
Allocate storage for the given number of elements of a storable type in the pool, but leave room for an extra element to signal the end of the array.
Allocate the given number of bytes of storage in the pool.
Allocate storage for a value in the given pool and marshal the value into this storage.
Allocate consecutive storage for a list of values in the given pool and marshal these values into it.
Allocate consecutive storage for a list of values in the given pool and marshal these values into it, terminating the end with the given marker.
Adjust the storage area for an element in the pool to the given size of the required type.
Adjust the size of an array in the given pool.
Adjust the size of an array with an end marker in the given pool.
Execute an action with a fresh memory pool, which gets automatically deallocated (including its contents) after the action has finished.
Advances the given address by the given offset in bytes.
Reverse the order of the bits in a Word16.
Reverse the order of the bits in a Word32.
Reverse the order of the bits in a Word64.
Reverse the order of the bits in a Word8.
Release the storage associated with the given FunPtr, which must have been obtained from a wrapper stub. This should be called whenever the return value from a foreign import wrapper function is no longer required; otherwise, the storage it uses will leak.
casts an IntPtr to a Ptr
casts a Ptr to an IntPtr
casts a Ptr to a WordPtr
casts a WordPtr to a Ptr
Given an arbitrary address and an alignment constraint,
alignPtr yields the next higher address that fulfills the
alignment constraint. An alignment constraint x is fulfilled by
any address divisible by x. This operation is idempotent.
Computes the offset required to get from the second to the first argument. We have
p2 == p1 `plusPtr` (p2 `minusPtr` p1)The constant nullFunPtr contains a distinguished value of FunPtr that is not associated with a valid memory location.
A signed integral type that can be losslessly converted to and from
Ptr. This type is also compatible with the C99 type intptr_t, and
can be marshalled to and from that type safely.
Instances14Bounded, Enum, Eq, Integral, Data, Num, …
Bounded IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrEnum IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrEq IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrIntegral IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrData IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrOrd IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrRead IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrReal IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrShow IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrIx IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrBits IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrFiniteBits IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrStorable IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Ptr
An unsigned integral type that can be losslessly converted to and from
Ptr. This type is also compatible with the C99 type uintptr_t, and
can be marshalled to and from that type safely.
Instances14Bounded, Enum, Eq, Integral, Data, Num, …
Bounded WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrEnum WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrEq WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrIntegral WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrData WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrOrd WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrRead WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrReal WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrShow WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrIx WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrBits WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrFiniteBits WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.PtrStorable WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Ptr
module Foreign.Marshal.Compat