Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module is not part of auto-generated code based on vk.xml. Instead, it is hand-written to provide common types and classes.
Synopsis
- data FlagType
- type FlagMask = FlagMask
- type FlagBit = FlagBit
- bitToMask :: Coercible (x FlagBit) (x FlagMask) => x FlagBit -> x FlagMask
- maskToBits :: (Bits (x FlagMask), Coercible (x FlagBit) (x FlagMask)) => x FlagMask -> [x FlagBit]
- class (VulkanStruct (StructRep a), IsVkStruct a) => VulkanMarshal a where
- type StructRep a :: StructMeta
- newVkData :: forall a. VulkanMarshal a => (Ptr a -> IO ()) -> IO a
- mallocVkData :: forall a. VulkanMarshal a => IO a
- mallocVkDataArray :: forall a. VulkanMarshal a => Int -> IO (Ptr a, [a])
- unsafePtr :: IsVkStruct a => a -> Ptr a
- fromForeignPtr :: forall a. VulkanMarshal a => ForeignPtr a -> IO a
- toForeignPtr :: IsVkStruct a => a -> IO (ForeignPtr a)
- toPlainForeignPtr :: IsVkStruct a => a -> IO (ForeignPtr a)
- touchVkData :: IsVkStruct a => a -> IO ()
- class VulkanPtr ptr where
- vkNullPtr :: ptr a
- newtype VkPtr a = VkPtr Word64
- pattern VK_ZERO_FLAGS :: Bits a => a
- pattern VK_NULL_HANDLE :: (Eq (ptr a), VulkanPtr ptr) => ptr a
- pattern VK_NULL :: (Eq (ptr a), VulkanPtr ptr) => ptr a
- clearStorable :: Storable a => Ptr a -> IO ()
- withPtr :: VulkanMarshal a => a -> (Ptr a -> IO b) -> IO b
- type StructFields a = SFields (StructRep a)
- type CUnionType a = SIsUnion (StructRep a)
- type ReturnedOnly a = SIsReturnedOnly (StructRep a)
- type StructExtends a = SStructExtends (StructRep a)
- type StructFieldNames (a :: Type) = FieldNames (StructFields a)
- type HasField (fname :: Symbol) (a :: Type) = (VulkanMarshal a, VulkanField (FieldRep fname a))
- type FieldRep (fname :: Symbol) (a :: Type) = GetFieldMeta (ErrorNoSuchField fname a) fname (StructFields a)
- type FieldType (fname :: Symbol) (a :: Type) = FType (FieldRep fname a)
- type FieldOptional (fname :: Symbol) (a :: Type) = FOptional (FieldRep fname a)
- type FieldOffset (fname :: Symbol) (a :: Type) = FByteOffset (FieldRep fname a)
- type FieldIsArray (fname :: Symbol) (a :: Type) = IsArrayLen (FLength (FieldRep fname a))
- type FieldArrayLength (fname :: Symbol) (a :: Type) = FLength (FieldRep fname a)
- type CanReadField (fname :: Symbol) (a :: Type) = (HasField fname a, IsTrue (ErrorNotReadableField fname a) (FCanRead (FieldRep fname a)), Storable (FieldType fname a))
- type CanWriteField (fname :: Symbol) (a :: Type) = (HasField fname a, IsTrue (ErrorNotWritableField fname a) (FCanWrite (FieldRep fname a)), Storable (FieldType fname a))
- type CanReadFieldArray (fname :: Symbol) (a :: Type) = CanReadField fname a
- type CanWriteFieldArray (fname :: Symbol) (a :: Type) = CanWriteField fname a
- fieldOptional :: forall (fname :: Symbol) (a :: Type). HasField fname a => Bool
- fieldOffset :: forall (fname :: Symbol) (a :: Type). HasField fname a => Int
- fieldArrayLength :: forall (fname :: Symbol) (a :: Type). HasField fname a => Int
- getField :: forall (fname :: Symbol) (a :: Type). CanReadField fname a => a -> FieldType fname a
- readField :: forall (fname :: Symbol) (a :: Type). CanReadField fname a => Ptr a -> IO (FieldType fname a)
- writeField :: forall (fname :: Symbol) (a :: Type). CanWriteField fname a => Ptr a -> FieldType fname a -> IO ()
- getFieldArrayUnsafe :: forall (fname :: Symbol) (a :: Type). CanReadFieldArray fname a => Int -> a -> FieldType fname a
- readFieldArrayUnsafe :: forall (fname :: Symbol) (a :: Type). CanReadFieldArray fname a => Int -> Ptr a -> IO (FieldType fname a)
- writeFieldArrayUnsafe :: forall (fname :: Symbol) (a :: Type). CanWriteFieldArray fname a => Int -> Ptr a -> FieldType fname a -> IO ()
- getFieldArray :: forall fname idx a. (CanReadFieldArray fname a, IndexInBounds fname idx a, KnownNat idx) => a -> FieldType fname a
- readFieldArray :: forall fname idx a. (CanReadFieldArray fname a, IndexInBounds fname idx a, KnownNat idx) => Ptr a -> IO (FieldType fname a)
- writeFieldArray :: forall fname idx a. (CanWriteFieldArray fname a, IndexInBounds fname idx a, KnownNat idx) => Ptr a -> FieldType fname a -> IO ()
- type IndexInBounds (s :: Symbol) (i :: Nat) (a :: Type) = IndexInBounds' s i a (CmpNat i (FieldArrayLength s a))
- class VulkanFields (SFields m) => VulkanStruct (m :: StructMeta) where
- class (Show (FType m), Storable (FType m)) => VulkanField (m :: FieldMeta) where
- class VulkanFields (ms :: [FieldMeta]) where
- withField :: forall (fname :: Symbol) (r :: Type) (errMsg :: ErrorMessage). KnownSymbol fname => Proxy# fname -> Proxy# errMsg -> (VulkanField (GetFieldMeta errMsg fname ms) => r) -> r
- enumerateFields :: forall (a :: Type). (forall (m :: FieldMeta). VulkanField m => Proxy# m -> a -> a) -> a -> a
- class KnownBool (b :: Bool) where
- data FieldMeta = FieldMeta Symbol Type Bool Nat Nat Bool Bool
- data StructMeta = StructMeta Symbol Type Nat Nat [FieldMeta] Bool Bool [Type]
- mallocForeignPtr :: Storable a => IO (ForeignPtr a)
- withForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b
- addForeignPtrFinalizer :: FinalizerPtr a -> ForeignPtr a -> IO ()
- data Int8
- data Int16
- data Int32
- data Int64
- data Word8
- data Word16
- data Word32
- data Word64
- data Ptr a
- data FunPtr a
- data Void
- type CString = Ptr CChar
- newtype CInt = CInt Int32
- newtype CSize = CSize Word64
- newtype CChar = CChar Int8
- newtype CWchar = CWchar Int32
- newtype CULong = CULong Word64
- withCStringField :: forall fname a b. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => a -> (CString -> IO b) -> IO b
- unsafeCStringField :: forall fname a. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => a -> CString
- getStringField :: forall fname a. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => a -> String
- readStringField :: forall fname a. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => Ptr a -> IO String
- writeStringField :: forall fname a. (CanWriteFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => Ptr a -> String -> IO ()
- cmpCStrings :: CString -> CString -> Ordering
- cmpCStringsN :: CString -> CString -> Int -> Ordering
Documentation
bitToMask :: Coercible (x FlagBit) (x FlagMask) => x FlagBit -> x FlagMask Source #
Convert a single bit (XxxBits
) to a bitmask (XxxFlags
)
maskToBits :: (Bits (x FlagMask), Coercible (x FlagBit) (x FlagMask)) => x FlagMask -> [x FlagBit] Source #
List all set bits of a bitmask (XxxFlags
) in the increasing order.
class (VulkanStruct (StructRep a), IsVkStruct a) => VulkanMarshal a Source #
All Vulkan structures are stored as-is in byte arrays to avoid any overheads for wrapping and unwrapping haskell values. VulkanMarshal provides an interfaces to write and read these structures in an imperative way.
type StructRep a :: StructMeta Source #
Instances
newVkData :: forall a. VulkanMarshal a => (Ptr a -> IO ()) -> IO a Source #
Allocate a pinned aligned byte array to keep vulkan data structure and fill it using a foreign function.
Note, the function is supposed to use newAlignedPinnedByteArray#
and does not guarantee to fill memory with zeroes.
Use clearStorable
to make sure all bytes are set to zero.
Note, the memory is managed by GHC, thus no need for freeing it manually.
mallocVkData :: forall a. VulkanMarshal a => IO a Source #
Allocate a pinned aligned byte array to keep vulkan data structure.
Note, the function is supposed to use newAlignedPinnedByteArray#
and does not guarantee to fill memory with zeroes.
Use clearStorable
to make sure all bytes are set to zero.
Note, the memory is managed by GHC, thus no need for freeing it manually.
mallocVkDataArray :: forall a. VulkanMarshal a => Int -> IO (Ptr a, [a]) Source #
Allocate a pinned aligned byte array to keep vulkan data structures. Returned `Ptr a` points to the first element in the contiguous array of returned structures. Returned list elements point to the same memory area. This function is unsafe in two ways:
- Several structures are stored next to each other, with no gaps; it would break its alignment if the size is not multiple of alignment.
- Returned pointer is not tracked by GHC as a reference to the managed memory. Thus, the array can be GCed if all references to the returned list are lost.
Note, the function is supposed to use newAlignedPinnedByteArray#
and does not guarantee to fill memory with zeroes.
Use clearStorable
to make sure all bytes are set to zero.
Note, the memory is managed by GHC, thus no need for freeing it manually.
unsafePtr :: IsVkStruct a => a -> Ptr a Source #
Get pointer to vulkan structure. Note, the address is only valid as long as a given vulkan structure exists. Structures created with newVkData are stored in pinned byte arrays, so their memory is maintained by Haskell GC.
fromForeignPtr :: forall a. VulkanMarshal a => ForeignPtr a -> IO a Source #
Get vulkan structure referenced by a ForeignPtr
trying to avoid copying data.
This function does copy data if called on an unmanaged ForeignPtr
(i.e. one created from ordinary Ptr
using something like newForeignPtr
.).
This function does not copy data if called on a managed ForeignPtr
(i.e. one created using mallocForeignPtr
, or toForeignPtr
, or toPlainForeignPtr
).
Note, fromForeignPtr
does not copy finalizers of ForeignPtr
.
Thus, if all references to original ForeignPtr
are lost,
its attached finalizers may run even if the created structure is alive.
toForeignPtr :: IsVkStruct a => a -> IO (ForeignPtr a) Source #
Create a ForeignPtr
referencing the structure without copying data.
toPlainForeignPtr :: IsVkStruct a => a -> IO (ForeignPtr a) Source #
Create a ForeignPtr
referencing the structure without copying data.
This version of a pointer carries no finalizers.
It is not possible to add a finalizer to a ForeignPtr created with
toPlainForeignPtr
.
Attempts to add a finalizer to a ForeignPtr created this way, or to
finalize such a pointer, will throw an exception.
touchVkData :: IsVkStruct a => a -> IO () Source #
Make sure this data is alive at a given point in a sequence of IO actions.
VK_DEFINE_NON_DISPATCHABLE_HANDLE
Non-dispatchable handles are represented as VkPtr
Represented as Word64
#if !defined(VK_DEFINE_NON_DISPATCHABLE_HANDLE) #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object; #else #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object; #endif #endif
Instances
VulkanPtr VkPtr Source # | |
Defined in Graphics.Vulkan.Marshal | |
Eq (VkPtr a) Source # | |
Ord (VkPtr a) Source # | |
Show (VkPtr a) Source # | |
Storable (VkPtr a) Source # | |
pattern VK_ZERO_FLAGS :: Bits a => a Source #
A synonym for zeroBits
pattern VK_NULL_HANDLE :: (Eq (ptr a), VulkanPtr ptr) => ptr a Source #
#define VK_NULL_HANDLE 0
pattern VK_NULL :: (Eq (ptr a), VulkanPtr ptr) => ptr a Source #
Null pointer (either dispatchable or non-dispatchable)
clearStorable :: Storable a => Ptr a -> IO () Source #
Fill all bytes to zero getting data size from Storable
instance.
withPtr :: VulkanMarshal a => a -> (Ptr a -> IO b) -> IO b Source #
Run some operation with a pointer to vulkan structure.
Should be used with care:
the structure pretends to be immutable, so it is better to only read
from the pointed memory area, not to write.
If an action needs to write something to the pointer, use newVkData
.
Type-indexed access to struct members
type StructFields a = SFields (StructRep a) Source #
Descriptions of all fields of a vulkan struct
type CUnionType a = SIsUnion (StructRep a) Source #
Whether this type is a C union. Otherwise this is a C structure.
type ReturnedOnly a = SIsReturnedOnly (StructRep a) Source #
Notes that this struct or union is going to be filled in by the API, rather than an application filling it out and passing it to the API.
type StructExtends a = SStructExtends (StructRep a) Source #
Comma-separated list of structures whose "pNext" can include this type.
type StructFieldNames (a :: Type) = FieldNames (StructFields a) Source #
type HasField (fname :: Symbol) (a :: Type) = (VulkanMarshal a, VulkanField (FieldRep fname a)) Source #
A Constraint: a vulkan struct must have a field with a given name.
type FieldRep (fname :: Symbol) (a :: Type) = GetFieldMeta (ErrorNoSuchField fname a) fname (StructFields a) Source #
Type-level description of a Vulkan structure field.
type FieldType (fname :: Symbol) (a :: Type) = FType (FieldRep fname a) Source #
Type of a field in a vulkan structure or union.
type FieldOptional (fname :: Symbol) (a :: Type) = FOptional (FieldRep fname a) Source #
Whether this field marked optional in vulkan specification.
Usually, this means that VK_NULL
can be written in place
of this field.
type FieldOffset (fname :: Symbol) (a :: Type) = FByteOffset (FieldRep fname a) Source #
Offset of a field in bytes.
type FieldIsArray (fname :: Symbol) (a :: Type) = IsArrayLen (FLength (FieldRep fname a)) Source #
Whether this field is a fixed-length array stored directly in a struct.
type FieldArrayLength (fname :: Symbol) (a :: Type) = FLength (FieldRep fname a) Source #
Length of an array that is a field of a structure or union
type CanReadField (fname :: Symbol) (a :: Type) = (HasField fname a, IsTrue (ErrorNotReadableField fname a) (FCanRead (FieldRep fname a)), Storable (FieldType fname a)) Source #
type CanWriteField (fname :: Symbol) (a :: Type) = (HasField fname a, IsTrue (ErrorNotWritableField fname a) (FCanWrite (FieldRep fname a)), Storable (FieldType fname a)) Source #
type CanReadFieldArray (fname :: Symbol) (a :: Type) = CanReadField fname a Source #
type CanWriteFieldArray (fname :: Symbol) (a :: Type) = CanWriteField fname a Source #
fieldOptional :: forall (fname :: Symbol) (a :: Type). HasField fname a => Bool Source #
Whether this field marked optional in vulkan specification.
Usually, this means that VK_NULL
can be written in place
of this field.
fieldOffset :: forall (fname :: Symbol) (a :: Type). HasField fname a => Int Source #
Offset of a field in bytes.
fieldArrayLength :: forall (fname :: Symbol) (a :: Type). HasField fname a => Int Source #
Length of an array that is a field of a structure or union.
Returns 1
if this field is not an array.
getField :: forall (fname :: Symbol) (a :: Type). CanReadField fname a => a -> FieldType fname a Source #
readField :: forall (fname :: Symbol) (a :: Type). CanReadField fname a => Ptr a -> IO (FieldType fname a) Source #
writeField :: forall (fname :: Symbol) (a :: Type). CanWriteField fname a => Ptr a -> FieldType fname a -> IO () Source #
getFieldArrayUnsafe :: forall (fname :: Symbol) (a :: Type). CanReadFieldArray fname a => Int -> a -> FieldType fname a Source #
Index an array-type field. No bound checks.
readFieldArrayUnsafe :: forall (fname :: Symbol) (a :: Type). CanReadFieldArray fname a => Int -> Ptr a -> IO (FieldType fname a) Source #
Read from an array-type field. No bound checks.
writeFieldArrayUnsafe :: forall (fname :: Symbol) (a :: Type). CanWriteFieldArray fname a => Int -> Ptr a -> FieldType fname a -> IO () Source #
Write to an array-type field. No bound checks.
getFieldArray :: forall fname idx a. (CanReadFieldArray fname a, IndexInBounds fname idx a, KnownNat idx) => a -> FieldType fname a Source #
readFieldArray :: forall fname idx a. (CanReadFieldArray fname a, IndexInBounds fname idx a, KnownNat idx) => Ptr a -> IO (FieldType fname a) Source #
writeFieldArray :: forall fname idx a. (CanWriteFieldArray fname a, IndexInBounds fname idx a, KnownNat idx) => Ptr a -> FieldType fname a -> IO () Source #
type IndexInBounds (s :: Symbol) (i :: Nat) (a :: Type) = IndexInBounds' s i a (CmpNat i (FieldArrayLength s a)) Source #
Type-level info about Structs
class VulkanFields (SFields m) => VulkanStruct (m :: StructMeta) where Source #
type SName m :: Symbol Source #
type SFields m :: [FieldMeta] Source #
type SIsUnion m :: Bool Source #
type SIsReturnedOnly m :: Bool Source #
type SStructExtends m :: [Type] Source #
Instances
(KnownSymbol structName, KnownNat size, KnownNat alignment, VulkanFields fields, KnownBool isUnion, KnownBool isReturnedOnly) => VulkanStruct (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) Source # | |
Defined in Graphics.Vulkan.Marshal.Internal type SName (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: Symbol Source # type SType (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: Type Source # type SSize (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: Nat Source # type SAlign (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: Nat Source # type SFields (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: [FieldMeta] Source # type SIsUnion (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: Bool Source # type SIsReturnedOnly (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: Bool Source # type SStructExtends (StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends) :: [Type] Source # |
class (Show (FType m), Storable (FType m)) => VulkanField (m :: FieldMeta) where Source #
type FName m :: Symbol Source #
type FOptional m :: Bool Source #
type FByteOffset m :: Nat Source #
type FLength m :: Nat Source #
fByteOffset :: Int Source #
Instances
(KnownSymbol fieldName, Show t, Storable t, KnownBool optional, KnownNat byteOffset, KnownNat length, KnownBool canRead, KnownBool canWrite) => VulkanField (FieldMeta fieldName t optional byteOffset length canRead canWrite) Source # | |
Defined in Graphics.Vulkan.Marshal.Internal type FName (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Symbol Source # type FType (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Type Source # type FOptional (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Bool Source # type FByteOffset (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Nat Source # type FLength (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Nat Source # type FCanRead (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Bool Source # type FCanWrite (FieldMeta fieldName t optional byteOffset length canRead canWrite) :: Bool Source # |
class VulkanFields (ms :: [FieldMeta]) where Source #
withField :: forall (fname :: Symbol) (r :: Type) (errMsg :: ErrorMessage). KnownSymbol fname => Proxy# fname -> Proxy# errMsg -> (VulkanField (GetFieldMeta errMsg fname ms) => r) -> r Source #
enumerateFields :: forall (a :: Type). (forall (m :: FieldMeta). VulkanField m => Proxy# m -> a -> a) -> a -> a Source #
Instances
VulkanFields ([] :: [FieldMeta]) Source # | |
Defined in Graphics.Vulkan.Marshal.Internal withField :: KnownSymbol fname => Proxy# fname -> Proxy# errMsg -> (VulkanField (GetFieldMeta errMsg fname []) -> r) -> r Source # enumerateFields :: (forall (m :: FieldMeta). VulkanField m => Proxy# m -> a -> a) -> a -> a Source # | |
(VulkanField m, VulkanFields ms) => VulkanFields (m ': ms) Source # | |
Defined in Graphics.Vulkan.Marshal.Internal withField :: KnownSymbol fname => Proxy# fname -> Proxy# errMsg -> (VulkanField (GetFieldMeta errMsg fname (m ': ms)) -> r) -> r Source # enumerateFields :: (forall (m0 :: FieldMeta). VulkanField m0 => Proxy# m0 -> a -> a) -> a -> a Source # |
class KnownBool (b :: Bool) where Source #
This class give a term-level boolean associated with a type-level boolean.
The same as KnownNat
for integers.
FieldMeta fieldName fieldType optional byteOffset length canRead canWrite
represents a Vulkan structure field at the type level.
Instances
VulkanFields ([] :: [FieldMeta]) Source # | |
Defined in Graphics.Vulkan.Marshal.Internal withField :: KnownSymbol fname => Proxy# fname -> Proxy# errMsg -> (VulkanField (GetFieldMeta errMsg fname []) -> r) -> r Source # enumerateFields :: (forall (m :: FieldMeta). VulkanField m => Proxy# m -> a -> a) -> a -> a Source # | |
(VulkanField m, VulkanFields ms) => VulkanFields (m ': ms) Source # | |
Defined in Graphics.Vulkan.Marshal.Internal withField :: KnownSymbol fname => Proxy# fname -> Proxy# errMsg -> (VulkanField (GetFieldMeta errMsg fname (m ': ms)) -> r) -> r Source # enumerateFields :: (forall (m0 :: FieldMeta). VulkanField m0 => Proxy# m0 -> a -> a) -> a -> a Source # |
data StructMeta Source #
StructMeta structName structType size alignment fields isUnion isReturnedOnly structExtends
represents a Vulkan structure at the type level.
Re-exported functions from ForeignPtr
mallocForeignPtr :: Storable a => IO (ForeignPtr a) #
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.
withForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b #
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.
addForeignPtrFinalizer :: FinalizerPtr a -> ForeignPtr a -> IO () #
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.
Re-exported common types
8-bit signed integer type
Instances
Bounded Int8 | Since: base-2.1 |
Enum Int8 | Since: base-2.1 |
Eq Int8 | Since: base-2.1 |
Integral Int8 | Since: base-2.1 |
Num Int8 | Since: base-2.1 |
Ord Int8 | Since: base-2.1 |
Read Int8 | Since: base-2.1 |
Real Int8 | Since: base-2.1 |
Defined in GHC.Int toRational :: Int8 -> Rational # | |
Show Int8 | Since: base-2.1 |
Ix Int8 | Since: base-2.1 |
Storable Int8 | Since: base-2.1 |
Defined in Foreign.Storable | |
Bits Int8 | Since: base-2.1 |
Defined in GHC.Int (.&.) :: Int8 -> Int8 -> Int8 # (.|.) :: Int8 -> Int8 -> Int8 # complement :: Int8 -> Int8 # shift :: Int8 -> Int -> Int8 # rotate :: Int8 -> Int -> Int8 # setBit :: Int8 -> Int -> Int8 # clearBit :: Int8 -> Int -> Int8 # complementBit :: Int8 -> Int -> Int8 # testBit :: Int8 -> Int -> Bool # bitSizeMaybe :: Int8 -> Maybe Int # shiftL :: Int8 -> Int -> Int8 # unsafeShiftL :: Int8 -> Int -> Int8 # shiftR :: Int8 -> Int -> Int8 # unsafeShiftR :: Int8 -> Int -> Int8 # rotateL :: Int8 -> Int -> Int8 # | |
FiniteBits Int8 | Since: base-4.6.0.0 |
Defined in GHC.Int |
16-bit signed integer type
Instances
32-bit signed integer type
Instances
64-bit signed integer type
Instances
8-bit unsigned integer type
Instances
16-bit unsigned integer type
Instances
32-bit unsigned integer type
Instances
64-bit unsigned integer type
Instances
A value of type
represents a pointer to an object, or an
array of objects, which may be marshalled to or from Haskell values
of type Ptr
aa
.
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
.
Instances
VulkanPtr Ptr Source # | |
Defined in Graphics.Vulkan.Marshal | |
Generic1 (URec (Ptr ()) :: k -> Type) | |
Eq (Ptr a) | Since: base-2.1 |
Ord (Ptr a) | Since: base-2.1 |
Show (Ptr a) | Since: base-2.1 |
Storable (Ptr a) | Since: base-2.1 |
Functor (URec (Ptr ()) :: Type -> Type) | Since: base-4.9.0.0 |
Foldable (URec (Ptr ()) :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => URec (Ptr ()) m -> m # foldMap :: Monoid m => (a -> m) -> URec (Ptr ()) a -> m # foldr :: (a -> b -> b) -> b -> URec (Ptr ()) a -> b # foldr' :: (a -> b -> b) -> b -> URec (Ptr ()) a -> b # foldl :: (b -> a -> b) -> b -> URec (Ptr ()) a -> b # foldl' :: (b -> a -> b) -> b -> URec (Ptr ()) a -> b # foldr1 :: (a -> a -> a) -> URec (Ptr ()) a -> a # foldl1 :: (a -> a -> a) -> URec (Ptr ()) a -> a # toList :: URec (Ptr ()) a -> [a] # null :: URec (Ptr ()) a -> Bool # length :: URec (Ptr ()) a -> Int # elem :: Eq a => a -> URec (Ptr ()) a -> Bool # maximum :: Ord a => URec (Ptr ()) a -> a # minimum :: Ord a => URec (Ptr ()) a -> a # | |
Traversable (URec (Ptr ()) :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Traversable | |
Eq (URec (Ptr ()) p) | Since: base-4.9.0.0 |
Ord (URec (Ptr ()) p) | Since: base-4.9.0.0 |
Defined in GHC.Generics compare :: URec (Ptr ()) p -> URec (Ptr ()) p -> Ordering # (<) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (<=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (>) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (>=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # max :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p # min :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p # | |
Generic (URec (Ptr ()) p) | |
data URec (Ptr ()) (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 |
type Rep1 (URec (Ptr ()) :: k -> Type) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
type Rep (URec (Ptr ()) p) | Since: base-4.9.0.0 |
Defined in GHC.Generics |
A value of type
is a pointer to a function callable
from foreign code. The type FunPtr
aa
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
or a renaming of any of these usingStablePtr
anewtype
. - the return type is either a marshallable foreign type or has the form
whereIO
tt
is a marshallable foreign type or()
.
A value of type
may be a pointer to a foreign function,
either returned by another foreign function or imported with a
a static address import likeFunPtr
a
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 -> IntFunction
Instances
Eq (FunPtr a) | |
Ord (FunPtr a) | |
Show (FunPtr a) | Since: base-2.1 |
Storable (FunPtr a) | Since: base-2.1 |
Defined in Foreign.Storable |
Uninhabited data type
Since: base-4.8.0.0
Instances
Eq Void | Since: base-4.8.0.0 |
Data Void | Since: base-4.8.0.0 |
Defined in Data.Void gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Void -> c Void # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Void # dataTypeOf :: Void -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Void) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Void) # gmapT :: (forall b. Data b => b -> b) -> Void -> Void # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r # gmapQ :: (forall d. Data d => d -> u) -> Void -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Void -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Void -> m Void # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Void -> m Void # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Void -> m Void # | |
Ord Void | Since: base-4.8.0.0 |
Read Void | Reading a Since: base-4.8.0.0 |
Show Void | Since: base-4.8.0.0 |
Ix Void | Since: base-4.8.0.0 |
Generic Void | |
Semigroup Void | Since: base-4.9.0.0 |
Exception Void | Since: base-4.8.0.0 |
Defined in Data.Void toException :: Void -> SomeException # fromException :: SomeException -> Maybe Void # displayException :: Void -> String # | |
type Rep Void | Since: base-4.8.0.0 |
Haskell type representing the C int
type.
Instances
Bounded CInt | |
Enum CInt | |
Eq CInt | |
Integral CInt | |
Num CInt | |
Ord CInt | |
Read CInt | |
Real CInt | |
Defined in Foreign.C.Types toRational :: CInt -> Rational # | |
Show CInt | |
Storable CInt | |
Defined in Foreign.C.Types | |
Bits CInt | |
Defined in Foreign.C.Types (.&.) :: CInt -> CInt -> CInt # (.|.) :: CInt -> CInt -> CInt # complement :: CInt -> CInt # shift :: CInt -> Int -> CInt # rotate :: CInt -> Int -> CInt # setBit :: CInt -> Int -> CInt # clearBit :: CInt -> Int -> CInt # complementBit :: CInt -> Int -> CInt # testBit :: CInt -> Int -> Bool # bitSizeMaybe :: CInt -> Maybe Int # shiftL :: CInt -> Int -> CInt # unsafeShiftL :: CInt -> Int -> CInt # shiftR :: CInt -> Int -> CInt # unsafeShiftR :: CInt -> Int -> CInt # rotateL :: CInt -> Int -> CInt # | |
FiniteBits CInt | |
Defined in Foreign.C.Types |
Haskell type representing the C size_t
type.
Instances
Bounded CSize | |
Enum CSize | |
Eq CSize | |
Integral CSize | |
Num CSize | |
Ord CSize | |
Read CSize | |
Real CSize | |
Defined in Foreign.C.Types toRational :: CSize -> Rational # | |
Show CSize | |
Storable CSize | |
Bits CSize | |
Defined in Foreign.C.Types (.&.) :: CSize -> CSize -> CSize # (.|.) :: CSize -> CSize -> CSize # xor :: CSize -> CSize -> CSize # complement :: CSize -> CSize # shift :: CSize -> Int -> CSize # rotate :: CSize -> Int -> CSize # setBit :: CSize -> Int -> CSize # clearBit :: CSize -> Int -> CSize # complementBit :: CSize -> Int -> CSize # testBit :: CSize -> Int -> Bool # bitSizeMaybe :: CSize -> Maybe Int # shiftL :: CSize -> Int -> CSize # unsafeShiftL :: CSize -> Int -> CSize # shiftR :: CSize -> Int -> CSize # unsafeShiftR :: CSize -> Int -> CSize # rotateL :: CSize -> Int -> CSize # | |
FiniteBits CSize | |
Defined in Foreign.C.Types finiteBitSize :: CSize -> Int # countLeadingZeros :: CSize -> Int # countTrailingZeros :: CSize -> Int # |
Haskell type representing the C char
type.
Instances
Bounded CChar | |
Enum CChar | |
Eq CChar | |
Integral CChar | |
Num CChar | |
Ord CChar | |
Read CChar | |
Real CChar | |
Defined in Foreign.C.Types toRational :: CChar -> Rational # | |
Show CChar | |
Storable CChar | |
Bits CChar | |
Defined in Foreign.C.Types (.&.) :: CChar -> CChar -> CChar # (.|.) :: CChar -> CChar -> CChar # xor :: CChar -> CChar -> CChar # complement :: CChar -> CChar # shift :: CChar -> Int -> CChar # rotate :: CChar -> Int -> CChar # setBit :: CChar -> Int -> CChar # clearBit :: CChar -> Int -> CChar # complementBit :: CChar -> Int -> CChar # testBit :: CChar -> Int -> Bool # bitSizeMaybe :: CChar -> Maybe Int # shiftL :: CChar -> Int -> CChar # unsafeShiftL :: CChar -> Int -> CChar # shiftR :: CChar -> Int -> CChar # unsafeShiftR :: CChar -> Int -> CChar # rotateL :: CChar -> Int -> CChar # | |
FiniteBits CChar | |
Defined in Foreign.C.Types finiteBitSize :: CChar -> Int # countLeadingZeros :: CChar -> Int # countTrailingZeros :: CChar -> Int # |
Haskell type representing the C wchar_t
type.
Instances
Bounded CWchar | |
Enum CWchar | |
Defined in Foreign.C.Types | |
Eq CWchar | |
Integral CWchar | |
Num CWchar | |
Ord CWchar | |
Read CWchar | |
Real CWchar | |
Defined in Foreign.C.Types toRational :: CWchar -> Rational # | |
Show CWchar | |
Storable CWchar | |
Bits CWchar | |
Defined in Foreign.C.Types (.&.) :: CWchar -> CWchar -> CWchar # (.|.) :: CWchar -> CWchar -> CWchar # xor :: CWchar -> CWchar -> CWchar # complement :: CWchar -> CWchar # shift :: CWchar -> Int -> CWchar # rotate :: CWchar -> Int -> CWchar # setBit :: CWchar -> Int -> CWchar # clearBit :: CWchar -> Int -> CWchar # complementBit :: CWchar -> Int -> CWchar # testBit :: CWchar -> Int -> Bool # bitSizeMaybe :: CWchar -> Maybe Int # shiftL :: CWchar -> Int -> CWchar # unsafeShiftL :: CWchar -> Int -> CWchar # shiftR :: CWchar -> Int -> CWchar # unsafeShiftR :: CWchar -> Int -> CWchar # rotateL :: CWchar -> Int -> CWchar # | |
FiniteBits CWchar | |
Defined in Foreign.C.Types finiteBitSize :: CWchar -> Int # countLeadingZeros :: CWchar -> Int # countTrailingZeros :: CWchar -> Int # |
Haskell type representing the C unsigned long
type.
Instances
Bounded CULong | |
Enum CULong | |
Defined in Foreign.C.Types | |
Eq CULong | |
Integral CULong | |
Num CULong | |
Ord CULong | |
Read CULong | |
Real CULong | |
Defined in Foreign.C.Types toRational :: CULong -> Rational # | |
Show CULong | |
Storable CULong | |
Bits CULong | |
Defined in Foreign.C.Types (.&.) :: CULong -> CULong -> CULong # (.|.) :: CULong -> CULong -> CULong # xor :: CULong -> CULong -> CULong # complement :: CULong -> CULong # shift :: CULong -> Int -> CULong # rotate :: CULong -> Int -> CULong # setBit :: CULong -> Int -> CULong # clearBit :: CULong -> Int -> CULong # complementBit :: CULong -> Int -> CULong # testBit :: CULong -> Int -> Bool # bitSizeMaybe :: CULong -> Maybe Int # shiftL :: CULong -> Int -> CULong # unsafeShiftL :: CULong -> Int -> CULong # shiftR :: CULong -> Int -> CULong # unsafeShiftR :: CULong -> Int -> CULong # rotateL :: CULong -> Int -> CULong # | |
FiniteBits CULong | |
Defined in Foreign.C.Types finiteBitSize :: CULong -> Int # countLeadingZeros :: CULong -> Int # countTrailingZeros :: CULong -> Int # |
Utilities for string types
withCStringField :: forall fname a b. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => a -> (CString -> IO b) -> IO b Source #
Perform an action on a C string field. The string pointers should not be used outside the callback. It will point to a correct location only as long as the struct is alive.
unsafeCStringField :: forall fname a. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => a -> CString Source #
Get pointer to a memory location of the C string field in a structure.
getStringField :: forall fname a. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => a -> String Source #
readStringField :: forall fname a. (CanReadFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => Ptr a -> IO String Source #
writeStringField :: forall fname a. (CanWriteFieldArray fname a, FieldType fname a ~ CChar, VulkanMarshal a) => Ptr a -> String -> IO () Source #