Add explicit `{-# LANGUAGE CPP, PackageImports #-}` pragmas
[packages/haskell2010.git] / Foreign / Marshal / Array.hs
1 {-# LANGUAGE CPP, PackageImports #-}
2 #if __GLASGOW_HASKELL__ >= 701
3 {-# LANGUAGE Safe #-}
4 #endif
5
6 {- |
7 The module "Foreign.Marshal.Array" provides operations for marshalling Haskell
8 lists into monolithic arrays and vice versa. Most functions come in two
9 flavours: one for arrays terminated by a special termination element and one
10 where an explicit length parameter is used to determine the extent of an
11 array. The typical example for the former case are C's NUL terminated
12 strings. However, please note that C strings should usually be marshalled
13 using the functions provided by "Foreign.C.String" as
14 the Unicode encoding has to be taken into account. All functions specifically
15 operating on arrays that are terminated by a special termination element have
16 a name ending on @0@---e.g., 'mallocArray' allocates space for an
17 array of the given size, whereas 'mallocArray0' allocates space for one
18 more element to ensure that there is room for the terminator.
19 -}
20 module Foreign.Marshal.Array (
21 -- * Marshalling arrays
22
23 -- ** Allocation
24 --
25 mallocArray, -- :: Storable a => Int -> IO (Ptr a)
26 mallocArray0, -- :: Storable a => Int -> IO (Ptr a)
27
28 allocaArray, -- :: Storable a => Int -> (Ptr a -> IO b) -> IO b
29 allocaArray0, -- :: Storable a => Int -> (Ptr a -> IO b) -> IO b
30
31 reallocArray, -- :: Storable a => Ptr a -> Int -> IO (Ptr a)
32 reallocArray0, -- :: Storable a => Ptr a -> Int -> IO (Ptr a)
33
34 -- ** Marshalling
35 --
36 peekArray, -- :: Storable a => Int -> Ptr a -> IO [a]
37 peekArray0, -- :: (Storable a, Eq a) => a -> Ptr a -> IO [a]
38
39 pokeArray, -- :: Storable a => Ptr a -> [a] -> IO ()
40 pokeArray0, -- :: Storable a => a -> Ptr a -> [a] -> IO ()
41
42 -- ** Combined allocation and marshalling
43 --
44 newArray, -- :: Storable a => [a] -> IO (Ptr a)
45 newArray0, -- :: Storable a => a -> [a] -> IO (Ptr a)
46
47 withArray, -- :: Storable a => [a] -> (Ptr a -> IO b) -> IO b
48 withArray0, -- :: Storable a => a -> [a] -> (Ptr a -> IO b) -> IO b
49
50 withArrayLen, -- :: Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
51 withArrayLen0, -- :: Storable a => a -> [a] -> (Int -> Ptr a -> IO b) -> IO b
52
53 -- ** Copying
54
55 -- | (argument order: destination, source)
56 copyArray, -- :: Storable a => Ptr a -> Ptr a -> Int -> IO ()
57 moveArray, -- :: Storable a => Ptr a -> Ptr a -> Int -> IO ()
58
59 -- ** Finding the length
60 --
61 lengthArray0, -- :: (Storable a, Eq a) => a -> Ptr a -> IO Int
62
63 -- ** Indexing
64 --
65 advancePtr, -- :: Storable a => Ptr a -> Int -> Ptr a
66 ) where
67 import qualified "base" Foreign.Marshal.Array as Base
68 import "base" Foreign.Marshal.Array hiding (peekArray)
69 #if __GLASGOW_HASKELL__ >= 701
70 import "base" Foreign.Safe hiding (peekArray)
71 #else
72 import "base" Foreign hiding (peekArray)
73 #endif
74
75 -- |Convert an array of given length into a Haskell list.
76 --
77 peekArray :: Storable a => Int -> Ptr a -> IO [a]
78 peekArray = Base.peekArray