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