`M-x delete-trailing-whitespace`
[packages/haskell2010.git] / Foreign / Marshal.hs
1 {-# LANGUAGE PackageImports #-}
2
3 module Foreign.Marshal (
4 -- | The module "Foreign.Marshal" re-exports the other modules in the
5 -- @Foreign.Marshal@ hierarchy:
6
7 module Foreign.Marshal.Alloc,
8 module Foreign.Marshal.Array,
9 module Foreign.Marshal.Error,
10 -- Not in Haskell 2010:
11 -- , module Foreign.Marshal.Pool
12 module Foreign.Marshal.Utils,
13 -- | and provides one function:
14 unsafeLocalState
15 ) where
16
17 import "this" Foreign.Marshal.Alloc
18 import "this" Foreign.Marshal.Array
19 import "this" Foreign.Marshal.Error
20 -- Not in Haskell 2010:
21 -- import "this" Foreign.Marshal.Pool
22 import "this" Foreign.Marshal.Utils
23
24 import "base" System.IO.Unsafe
25
26 {- |
27 Sometimes an external entity is a pure function, except that it passes
28 arguments and/or results via pointers. The function
29 @unsafeLocalState@ permits the packaging of such entities as pure
30 functions.
31
32 The only IO operations allowed in the IO action passed to
33 @unsafeLocalState@ are (a) local allocation (@alloca@, @allocaBytes@
34 and derived operations such as @withArray@ and @withCString@), and (b)
35 pointer operations (@Foreign.Storable@ and @Foreign.Ptr@) on the
36 pointers to local storage, and (c) foreign functions whose only
37 observable effect is to read and/or write the locally allocated
38 memory. Passing an IO operation that does not obey these rules
39 results in undefined behaviour.
40
41 It is expected that this operation will be
42 replaced in a future revision of Haskell.
43 -}
44 unsafeLocalState :: IO a -> a
45 unsafeLocalState = unsafePerformIO