File: FFITypes.hs

package info (click to toggle)
haskell-libffi 0.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 92 kB
  • sloc: haskell: 316; makefile: 5
file content (85 lines) | stat: -rw-r--r-- 3,460 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{-# LANGUAGE ForeignFunctionInterface #-}
{- | The pointers exported and used by the C libffi describing basic ffi types. -}
module Foreign.LibFFI.FFITypes where

import Data.Int
import Data.Word
import Foreign.C.Types
import Foreign.Ptr
import Foreign.Storable

import Foreign.LibFFI.Internal

foreign import ccall unsafe "&" ffi_type_void :: Ptr CType
foreign import ccall unsafe "&" ffi_type_sint8 :: Ptr CType
foreign import ccall unsafe "&" ffi_type_uint8 :: Ptr CType
foreign import ccall unsafe "&" ffi_type_uint16 :: Ptr CType
foreign import ccall unsafe "&" ffi_type_sint16 :: Ptr CType
foreign import ccall unsafe "&" ffi_type_uint32 :: Ptr CType
foreign import ccall unsafe "&" ffi_type_sint32 :: Ptr CType
foreign import ccall unsafe "&" ffi_type_uint64 :: Ptr CType
foreign import ccall unsafe "&" ffi_type_sint64 :: Ptr CType
foreign import ccall unsafe "&" ffi_type_float  :: Ptr CType
foreign import ccall unsafe "&" ffi_type_double :: Ptr CType
foreign import ccall unsafe "&" ffi_type_pointer :: Ptr CType

ffi_type_uchar  :: Ptr CType
ffi_type_uchar  = ffi_type_uint8

ffi_type_schar  :: Ptr CType
ffi_type_schar  = ffi_type_sint8

ffi_type_wchar  :: Ptr CType
ffi_type_wchar  = case sizeOf (undefined :: CWchar) of
                    2   -> ffi_type_sint16
                    4   -> ffi_type_sint32
                    8   -> ffi_type_sint64
                    _   -> error "ffi_type_wchar of unsupported size"

ffi_type_size   :: Ptr CType
ffi_type_size   = case sizeOf (undefined :: CSize) of
                    4   -> ffi_type_uint32
                    8   -> ffi_type_uint64
                    _   -> error "ffi_type_size of unsupported size"

ffi_type_time   :: Ptr CType
ffi_type_time   = case sizeOf (undefined :: CTime) of
                    4   -> ffi_type_sint32
                    8   -> ffi_type_sint64
                    _   -> error "ffi_type_time of unsupported size"

ffi_type_uint   :: Ptr CType
ffi_type_uint   = case sizeOf (undefined :: CUInt) of
                    4   -> ffi_type_uint32
                    8   -> ffi_type_uint64
                    _   -> error "ffi_type_uint of unsupported size"

ffi_type_sint   :: Ptr CType
ffi_type_sint   = case sizeOf (undefined :: CInt) of
                    4   -> ffi_type_sint32
                    8   -> ffi_type_sint64
                    _   -> error "ffi_type_sint of unsupported size"

ffi_type_ulong  :: Ptr CType
ffi_type_ulong  = case sizeOf (undefined :: CULong) of
                    4   -> ffi_type_uint32
                    8   -> ffi_type_uint64
                    _   -> error "ffi_type_ulong of unsupported size"

ffi_type_slong  :: Ptr CType
ffi_type_slong  = case sizeOf (undefined :: CLong) of
                    4   -> ffi_type_sint32
                    8   -> ffi_type_sint64
                    _   -> error "ffi_type_slong of unsupported size"

ffi_type_hs_int :: Ptr CType
ffi_type_hs_int = case sizeOf (undefined :: Int) of
                    4   -> ffi_type_sint32
                    8   -> ffi_type_sint64
                    _   -> error "ffi_type_hs_int: unsupported sizeOf (_ :: Int)"

ffi_type_hs_word :: Ptr CType
ffi_type_hs_word = case sizeOf (undefined :: Word) of
                    4   -> ffi_type_uint32
                    8   -> ffi_type_uint64
                    _   -> error "ffi_type_hs_word: unsupported sizeOf (_ :: Word)"